[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.dotnet.framework.sdk

Problem with 'TcpClient'

Eugene Lerner

11/6/2003 7:15:00 PM

I execute these steps -

TcpClient MyTcpClient = new TcpClient( . );
MyTcpClient.Connect( . ); //Connect to Server
NetworkStream MyNetworkStream;
MyNetworkStream = MyTcpClient.GetStream( ); //Get Network
Stream
IAsyncResult MyAsyncResult = NetworkStream.BeginRead(
.. ); //Start asynchronous read
MyAsyncResult.AsyncWaitHandle.WaitOne( ); //Wait
infinitely for TCP Server to write something into socket
int ReadCount = MyNetworkStream.EndRead(
MyAsyncResult ); //Get number of bytes read

Here is a problem I'm having:
Sometimes "WaitOne" call returns but subsequent "EndRead"
returns 0 (zero) bytes were read from the socket. Could
this be that I'm doing something wrong or TCP server has
a bug?

Thank you

2 Answers

Feroze [MSFT]

11/6/2003 8:20:00 PM

0

That means that the peer closed the connection gracefully.You need to look
at the server code to see why the connection is getting closed.

--
Remove "user" from the email address to reply to the author.

This posting is provided "AS IS" with no warranties, and confers no rights

Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cp...




"Eugene Lerner" <elerner@trekds.com> wrote in message
news:027e01c3a49a$52d05650$a301280a@phx.gbl...
> I execute these steps -
>
> TcpClient MyTcpClient = new TcpClient( . );
> MyTcpClient.Connect( . ); //Connect to Server
> NetworkStream MyNetworkStream;
> MyNetworkStream = MyTcpClient.GetStream( ); //Get Network
> Stream
> IAsyncResult MyAsyncResult = NetworkStream.BeginRead(
> . ); //Start asynchronous read
> MyAsyncResult.AsyncWaitHandle.WaitOne( ); //Wait
> infinitely for TCP Server to write something into socket
> int ReadCount = MyNetworkStream.EndRead(
> MyAsyncResult ); //Get number of bytes read
>
> Here is a problem I'm having:
> Sometimes "WaitOne" call returns but subsequent "EndRead"
> returns 0 (zero) bytes were read from the socket. Could
> this be that I'm doing something wrong or TCP server has
> a bug?
>
> Thank you
>


Feroze [MSFT]

11/8/2003 3:39:00 AM

0

cant think of any. You should start a packet capture utility and record the
session. that will show you definitely who is closing the connection.

--
Remove "user" from the email address to reply to the author.

This posting is provided "AS IS" with no warranties, and confers no rights

Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cp...




"Eugene Lerner" <elerner@trekds.com> wrote in message
news:0a3f01c3a4a9$8648eba0$a001280a@phx.gbl...
> This is what I thought had happened. However TCP server
> programmer assured me that he always keeps connection
> open.
>
> Any other possible reasons for such odd behaviour?
>
> Thank you.
>
> >-----Original Message-----
> >That means that the peer closed the connection
> gracefully.You need to look
> >at the server code to see why the connection is getting
> closed.
> >
> >--
> >Remove "user" from the email address to reply to the
> author.
> >
> >This posting is provided "AS IS" with no warranties, and
> confers no rights
> >
> >Use of included script samples are subject to the terms
> specified at
> >http://www.microsoft.com/info/cp...
> >
> >
> >
> >
> >"Eugene Lerner" <elerner@trekds.com> wrote in message
> >news:027e01c3a49a$52d05650$a301280a@phx.gbl...
> >> I execute these steps -
> >>
> >> TcpClient MyTcpClient = new TcpClient( . );
> >> MyTcpClient.Connect( . ); //Connect to Server
> >> NetworkStream MyNetworkStream;
> >> MyNetworkStream = MyTcpClient.GetStream( ); //Get
> Network
> >> Stream
> >> IAsyncResult MyAsyncResult = NetworkStream.BeginRead(
> >> . ); //Start asynchronous read
> >> MyAsyncResult.AsyncWaitHandle.WaitOne( ); //Wait
> >> infinitely for TCP Server to write something into
> socket
> >> int ReadCount = MyNetworkStream.EndRead(
> >> MyAsyncResult ); //Get number of bytes read
> >>
> >> Here is a problem I'm having:
> >> Sometimes "WaitOne" call returns but
> subsequent "EndRead"
> >> returns 0 (zero) bytes were read from the socket. Could
> >> this be that I'm doing something wrong or TCP server
> has
> >> a bug?
> >>
> >> Thank you
> >>
> >
> >
> >.
> >