Click here to Skip to main content

C#

    RSS: RSS Feed
Home > Forums > C#

 
You must Sign In to use this message board. (secure sign-in)
 
Search this forum  
 FAQ
    Noise  Layout  Per page  Show 
  Refresh
AnswerRe: better way to make function returns Pinmember0x3c07:38 20 Nov '09  
AnswerRe: better way to make function returns Pinmembermusefan8:39 20 Nov '09  
GeneralRe: better way to make function returns PinmembernetJP12L9:34 20 Nov '09  
AnswerRe: better way to make function returns Pinmemberdojohansen11:59 23 Nov '09  
QuestionStream closes while reading a socket Pinmemberjoana.simoes6:11 20 Nov '09  
AnswerRe: Stream closes while reading a socket PinmemberPaulo Zemek6:57 20 Nov '09  
GeneralRe: Stream closes while reading a socket Pinmemberjoana.simoes7:19 20 Nov '09  
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 PinmemberPaulo Zemek8:44 22 Nov '09  
AnswerRe: Stream closes while reading a socket PinmvpLuc Pattyn7:27 20 Nov '09  
GeneralRe: Stream closes while reading a socket Pinmemberjoana.simoes1:13 23 Nov '09  
GeneralRe: Stream closes while reading a socket Pinmemberjoana.simoes1:39 23 Nov '09  
GeneralRe: Stream closes while reading a socket PinmvpLuc Pattyn1:43 23 Nov '09  
GeneralRe: Stream closes while reading a socket Pinmemberjoana.simoes4:56 23 Nov '09  
NewsRe: Stream closes while reading a socket Pinmemberjoana.simoes7:43 23 Nov '09  
AnswerRe: Stream closes while reading a socket Pinmemberdojohansen12:15 23 Nov '09  
NewsRe: Stream closes while reading a socket Pinmemberjoana.simoes2:37 24 Nov '09  
QuestionExcel Formatting. PinmemberFEMDEV5:47 20 Nov '09  
AnswerRe: Excel Formatting. Pinmembertoby319:16 20 Nov '09  
GeneralRe: Excel Formatting. PinmemberFEMDEV23:44 22 Nov '09  
QuestionSQLite Pinmemberjashimu4:26 20 Nov '09  
AnswerRe: SQLite PinmemberMeLight4:35 20 Nov '09  
GeneralRe: SQLite Pinmemberjashimu5:44 20 Nov '09  
GeneralRe: SQLite PinmvpPete O'Hanlon6:04 20 Nov '09  
GeneralRe: SQLite PinmemberPIEBALDconsult9:04 20 Nov '09  
GeneralRe: SQLite Pinmemberjashimu9:09 20 Nov '09  

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

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


Advertise | Privacy | Mobile
Web02 | 2.5.120210.1 | Last Updated 14 Feb 2012
Copyright © CodeProject, 1999-2012
All Rights Reserved. Terms of Use
Layout: fixed | fluid