Click here to Skip to main content
15,888,454 members
Home / Discussions / C#
   

C#

 
GeneralRe: better way to make function returns Pin
Saksida Bojan20-Nov-09 6:59
Saksida Bojan20-Nov-09 6:59 
AnswerRe: better way to make function returns Pin
0x3c020-Nov-09 6:38
0x3c020-Nov-09 6:38 
AnswerRe: better way to make function returns Pin
musefan20-Nov-09 7:39
musefan20-Nov-09 7:39 
GeneralRe: better way to make function returns Pin
netJP12L20-Nov-09 8:34
netJP12L20-Nov-09 8:34 
AnswerRe: better way to make function returns Pin
dojohansen23-Nov-09 10:59
dojohansen23-Nov-09 10:59 
QuestionStream closes while reading a socket Pin
joana.simoes20-Nov-09 5:11
joana.simoes20-Nov-09 5:11 
AnswerRe: Stream closes while reading a socket Pin
Paulo Zemek20-Nov-09 5:57
mvaPaulo Zemek20-Nov-09 5:57 
GeneralRe: Stream closes while reading a socket Pin
joana.simoes20-Nov-09 6:19
joana.simoes20-Nov-09 6:19 
Thanks a lot for the reply Paulo!!


Paulo Zemek wrote:
I think you should read from instream and write to outstream.
Maybe that's the problem (I am not sure, as I don't have the full source).



I think my names are perhaps not very clear, but I am reading from the WebResponse and writing to the HttpListenerContext.Response (which is carried to the callback)

Stream instream = response.GetResponseStream();
Stream outstream = context.Response.OutputStream;

int outcount = instream.Read(buffer, 0, buffer.Length);
while (outcount > 0)
{
    outstream.Write(buffer, 0, outcount);
    outcount = instream.Read(buffer, 0, buffer.Length);
}
// Close streams
instream.Close();
outstream.Close();




Paulo Zemek wrote:
Also, I think the best pattern is:
Create a TcpListener.
Start it.
In a loop, you accept a TcpClient, start a thread to process the client and continues in the loop accepting new requests.


I think I might have tried that approach: do you mean something like this?
TcpListener listener = new TcpListener(IPAddress.Any, m_port);
listener.Start();

while (true)
{
    Socket client = listener.AcceptSocket();
    ThreadPool.QueueUserWorkItem(ProcessSocket, client);
}


(Of course the socket client, could be a TcpListener client, but I'm not sure that makes much difference. This code is also getting into the "Stream closed exception").


Paulo Zemek wrote:
And, finally, maybe the connection is lost in the middle. This can happen (think about the stop button, for example). So, if the connection is closed, it's ok. Ignore this exception.


I just dont understand why the connection is closed! Is it getting a timeout for some reason? and why is it only happening when I have multiple requests?
(I have to add I am connecting to my server and I know by a fact that no one is accessing it and the connection is not closed, because I tested it) Confused | :confused:
GeneralRe: Stream closes while reading a socket Pin
Paulo Zemek22-Nov-09 7:44
mvaPaulo Zemek22-Nov-09 7:44 
AnswerRe: Stream closes while reading a socket Pin
Luc Pattyn20-Nov-09 6:27
sitebuilderLuc Pattyn20-Nov-09 6:27 
GeneralRe: Stream closes while reading a socket Pin
joana.simoes23-Nov-09 0:13
joana.simoes23-Nov-09 0:13 
GeneralRe: Stream closes while reading a socket Pin
joana.simoes23-Nov-09 0:39
joana.simoes23-Nov-09 0:39 
GeneralRe: Stream closes while reading a socket Pin
Luc Pattyn23-Nov-09 0:43
sitebuilderLuc Pattyn23-Nov-09 0:43 
GeneralRe: Stream closes while reading a socket Pin
joana.simoes23-Nov-09 3:56
joana.simoes23-Nov-09 3:56 
NewsRe: Stream closes while reading a socket Pin
joana.simoes23-Nov-09 6:43
joana.simoes23-Nov-09 6:43 
AnswerRe: Stream closes while reading a socket Pin
dojohansen23-Nov-09 11:15
dojohansen23-Nov-09 11:15 
NewsRe: Stream closes while reading a socket Pin
joana.simoes24-Nov-09 1:37
joana.simoes24-Nov-09 1:37 
QuestionExcel Formatting. Pin
FEMDEV20-Nov-09 4:47
FEMDEV20-Nov-09 4:47 
AnswerRe: Excel Formatting. Pin
toby3120-Nov-09 8:16
toby3120-Nov-09 8:16 
GeneralRe: Excel Formatting. Pin
FEMDEV22-Nov-09 22:44
FEMDEV22-Nov-09 22:44 
QuestionSQLite Pin
jashimu20-Nov-09 3:26
jashimu20-Nov-09 3:26 
AnswerRe: SQLite Pin
MeLight20-Nov-09 3:35
MeLight20-Nov-09 3:35 
GeneralRe: SQLite Pin
jashimu20-Nov-09 4:44
jashimu20-Nov-09 4:44 
GeneralRe: SQLite Pin
Pete O'Hanlon20-Nov-09 5:04
mvePete O'Hanlon20-Nov-09 5:04 
GeneralRe: SQLite Pin
PIEBALDconsult20-Nov-09 8:04
mvePIEBALDconsult20-Nov-09 8:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.