Re: blocking non blocking
- From: "Daniel" <DanielV@xxxxxxxxxxxxxxxx>
- Date: Thu, 6 Jul 2006 10:50:32 +0100
Ahh so in that case my code is fine and i wont have the problem of thousands
of threads being spawned and my solution is scalable yes?
"Arkady Frenkel" <arkadyf@xxxxxxxxxxxxxxxx> wrote in message
news:ORZNX3NoGHA.4176@xxxxxxxxxxxxxxxxxxxxxxx
No, that done on the same thread otherwise you can't use the same thread
context ( stack data and so on ...)
Arkady
"Daniel" <DanielV@xxxxxxxxxxxxxxxx> wrote in message
news:ueEYXMNoGHA.4864@xxxxxxxxxxxxxxxxxxxxxxx
I see. I coded mine to use asynchronous calls, (tcp stream), stays
connected for the duration of the client app.
I have thought that in an async set up that on connecting it spawns a
thread for that client?
Here is some of my server code, as you can see on every connect i fire
off the asyncallback method to handle the client connection. Which is
where i presumed a thread is spawned and handles that connection? Have i
missed out on some fundamental understanding and inadvertently coded this
correctly anyway?
public void Listen(int PortNo)
{
_portNo = PortNo;
try
{
//create the listening socket...
_socListener = new
Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
IPEndPoint ipLocal = new IPEndPoint ( IPAddress.Any ,_portNo);
//bind to local IP Address...
_socListener.Bind( ipLocal );
//start listening...
_socListener.Listen (4);
// create the call back for any client connections...
_socListener.BeginAccept(new AsyncCallback ( OnClientConnect ),null);
}
catch(SocketException se)
{
MessageBox.Show ( se.Message );
}
}
protected void OnClientConnect(IAsyncResult asyn)
{
try
{
_socWorker = _socListener.EndAccept (asyn);
ClientConnected();
WaitForData(_socWorker);
// create the call back for any client connections...
_socListener.BeginAccept(new AsyncCallback(OnClientConnect), null); //to
allow next client to be able to connect
}
catch(ObjectDisposedException)
{
Console.WriteLine("OnClientConnect: Connection closed
{0}",_socWorker.RemoteEndPoint.ToString());
}
catch(SocketException se)
{
MessageBox.Show ( se.Message, "OnClientConnect::NetServer" );
}
catch(Exception exc)
{
MessageBox.Show("NetServer::OnClientConnect-" + exc.Message,"Failed to
connect - " + exc.GetType());
}
}
protected virtual void WaitForData(System.Net.Sockets.Socket soc)
{
try
{
// if (soc.Connected)
// {
dvSocketPacket theSocPkt = new dvSocketPacket(_bufferSize);
theSocPkt.thisSocket = soc;
theSocPkt.remoteIP = soc.RemoteEndPoint;
// now start to listen for any data...
soc.BeginReceive(theSocPkt.dataBuffer, 0, theSocPkt.dataBuffer.Length,
SocketFlags.None, new AsyncCallback(OnDataReceived), theSocPkt);
// }
// else
// {
// disconnectEvent(soc.RemoteEndPoint);
//}
}
catch (SocketException se)
{
MessageBox.Show(se.Message, "Error while waiting for data");
}
}
.
- Follow-Ups:
- Re: blocking non blocking
- From: Arkady Frenkel
- Re: blocking non blocking
- References:
- Re: blocking non blocking
- From: Alexander Nickolov
- Re: blocking non blocking
- From: Daniel
- Re: blocking non blocking
- From: Arkady Frenkel
- Re: blocking non blocking
- From: Daniel
- Re: blocking non blocking
- From: Arkady Frenkel
- Re: blocking non blocking
- Prev by Date: Re: Does wireless provisioning services require Dialup networking ?
- Next by Date: Re: blocking non blocking
- Previous by thread: Re: blocking non blocking
- Next by thread: Re: blocking non blocking
- Index(es):
Relevant Pages
|