Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / Compact Framework / October 2004

Tip: Looking for answers? Try searching our database.

TCPClient/NetworkStream packet status problem

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Niklas - 26 Oct 2004 15:29 GMT
I'm having a problem with the TCPClient/NetworkStream that I can't get
around. When I send something on the socket I don't know if it's
received by the server or not. I always get IsCompleted. IsCompleted
== true no matter if the server receives the packet or not. After 2
minutes I get the socket timeout if the server is unreachable.

I know the following:
SetSocketOption – Send timeout is not implemented on Win CE
The default Send timeout is 2 minutes
I can use socket Keep Alive but that affects all sockets on the system

The commonly suggested solution:
Use a timer to se if there is a pending message.
Let the server send a response for each packet. (We use GPRS and would
like to keep the network traffic to a minimum)

My question is:
How can I see if a socket (or NetworkStream) has a pending packet?
Some how the network layer knows it since it reports it after 2
minutes.

Thanx,
Niklas

//TcpClient m_tcpClient;
private void Send()
{
  try
  {
     string tmpString = "Hello";
     Encoding encStr = Encoding.Default;
     Byte[] ByteGet = encStr.GetBytes(tmpString);
     m_tcpClient.BeginSend(ByteGet, 0, ByteGet.Length,
        0, new AsyncCallback(SendMsgCallBack),
        new SentMsgStatStruct(m_tcpClient, tmpString));
  }
  catch( Exception exc )
  {
     MessageBox.Show("Exception: " + exc.ToString());
  }
}

private void SendMsgCallBack(System.IAsyncResult ar)
{
  try
  {
     MessageBox.Show("Completed: " + ar.IsCompleted.ToString());
     MessageBox.Show("Completed Sync: " +
ar.CompletedSynchronously.ToString());
     socket.EndSend(ar);
  }
  catch( SocketException e )
  {
     MessageBox.Show("Socket exception: " + e.ToString());
  }
  catch( Exception exc )
  {
     MessageBox.Show("Exception: " + exc.ToString());
  }
}
Paul G. Tobey [eMVP] - 26 Oct 2004 16:35 GMT
At the socket level, *every* packet on a connection-oriented socket is
delivered.  The only indication that you can get that it was not delivered
is, as you saw, an exception indicating that the socket is down.

Keep-alive doesn't affect all sockets on the system; it's enabled on a
socket-by-socket basis (although the *settings* are global, of course).  For
that matter, keep-alive is only sent when the socket is idle, so it won't
help in your case.

The only way that I can think of to actually do what you're talking about is
to replace the WinSock layer yourself or implement your own version of TCP
on top of datagram packets (you'd be responsible for acknowledging receipt
of packets, deciding when a socket was timed-out, etc., so you'd be able to
do whatever you want).  Since this doesn't seem too practical to me, I'd
suggest that you either live with the time-out time you have now or bite the
bullet and implement a response to every message and your own 'send
time-out'.

Paul T.

> I'm having a problem with the TCPClient/NetworkStream that I can't get
> around. When I send something on the socket I don't know if it's
[quoted text clipped - 56 lines]
>   }
> }

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2010 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.