PC Review


Reply
Thread Tools Rate Thread

Async sockets on win98 [dotnet1.1]

 
 
GuidoD
Guest
Posts: n/a
 
      1st Aug 2005
Hi,

Is there some issue with asynchronous sockets on windows 98? (.NET framework
1.1)
I have a client application which connects using an async socket. All works
well on XP/2000/2003.
When running win98, after 20-25 minutes (activity or no activity) the socket
does not see
incoming data anymore and the socket needs to be reinitialized. the socket
can still send
data though and the connection is still open. The code works fine on hugher
windows versions.
I used socket workbench to make sure that the socket actually *is* recieving
data; ; but it does not know it's recieving anymore.

I'm using queue-based processing of incoming data in a separate thread to
minimize
interference with socket processing.

I'm using the following code (snippet originating from MSDN):

public sealed class CSocketPacket

{

public const int BUFFER_SIZE=1024;

public System.Net.Sockets.Socket thisSocket;

public byte[] dataBuffer = new byte[BUFFER_SIZE];

}


public sealed class AsyncSocketClient
{

// ... constructor etc

public void SendMessage(string message)

{

// if (message.StartsWith("CC_DIAL"))

// {

// Debugger.Break();

// }

try

{

byte[] bytes = System.Text.Encoding.ASCII.GetBytes(message);

m_socket.Send (bytes);

//System.Threading.Thread.Sleep(5000);

}

catch(SocketException se)

{

Trace.WriteLine("Socket disconnected in AsyncSocketClient::SendMessage");

Trace.WriteLine (se.Message );

if (this.RestartRequested!=null) this.RestartRequested(this, new
EventArgs());

}

}

public void WaitForData()

{

Trace.WriteLine("::WaitForData");

try

{

if ( pfnCallBack == null )

{

pfnCallBack = new AsyncCallback (OnDataReceived);

}

CSocketPacket theSocPkt = new CSocketPacket ();

theSocPkt.thisSocket = m_socket;

// now start to listen for any data...

m_asynResult = m_socket. BeginReceive (theSocPkt.dataBuffer
,0,theSocPkt.dataBuffer.Length ,SocketFlags.None,pfnCallBack,theSocPkt);

Trace.WriteLine("~WaitForData");

}

catch(SocketException sx)

{

Trace.WriteLine("Socket disconnected in AsyncSocketClient::WaitForData");

Trace.WriteLine (sx.Message );

if (m_connected)

if (this.RestartRequested!=null) this.RestartRequested(this, new
EventArgs());

}

catch(ObjectDisposedException ode)

{

reportException(ode);

}

Trace.WriteLine("WaitForData :: Finished");


}


public void OnDataReceived(IAsyncResult asyn)

{

Trace.WriteLine("::OnDataReceived");

try

{

CSocketPacket theSockId = (CSocketPacket)asyn.AsyncState ;

//end receive...

int iRx = 0 ;

iRx = theSockId.thisSocket.EndReceive (asyn);

char[] chars = new char[iRx + 1];

System.Text.Decoder d = System.Text.Encoding.ASCII.GetDecoder();

int charLen = d.GetChars(theSockId.dataBuffer, 0, iRx, chars, 0);

string data = new System.String(chars);

//Trace.WriteLine("[rcvd : " + data.Length.ToString() + " bytes]------");

//Trace.WriteLine("");

if (this.DataRecieved!=null)

this.DataRecieved(data, DateTime.Now);

}

catch (ObjectDisposedException ode)

{

Trace.WriteLine("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-");

Trace.WriteLine("\nEnding OnDataReceived: Socket has been closed\n");

reportException(ode);

Trace.WriteLine("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-");

return;

}

catch(SocketException sxception)

{

Trace.WriteLine("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-");

Trace.WriteLine("\nEnding OnDataReceived: Socket has been closed\n");

Trace.WriteLine("Socket disconnected in
AsyncSocketClient::OnDataReceived(IAsyncResult **result)");

reportException(sxception);

Trace.WriteLine("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-");

if (this.RestartRequested!=null) this.RestartRequested(this, new
EventArgs());

else

{

Trace.WriteLine("UNEXPECTED");

}

return;

}

catch(Exception exc)

{

Trace.WriteLine("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-");

Trace.WriteLine("\nContinuing OnDataReceived: unknown error\n");

reportException(exc);

Trace.WriteLine("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-");

}

Trace.WriteLine("~OnDataReceived");

// always wait for the next data if socket is not disconnected

WaitForData();

}

}






 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
writing an async client (sockets/async/thread) asharda@woh.rr.com Microsoft C# .NET 8 17th Mar 2008 10:04 PM
Async sockets news.eclipse.co.uk Microsoft Dot NET Compact Framework 2 12th Sep 2007 07:32 PM
Async sockets vs synch sockets and threads nyhetsgrupper@gmail.com Microsoft C# .NET 4 20th Sep 2006 04:06 AM
Async TCP Sockets mak Microsoft C# .NET 5 15th Jul 2005 11:23 AM
Async sockets Frane Roje Microsoft C# .NET 3 2nd Jul 2004 10:55 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:17 PM.