Why can't more than one connect at one time?
- From: "Dan" <dvazanias@xxxxxxx>
- Date: Thu, 9 Feb 2006 10:31:56 -0000
Hi guys
For those regularly replying to me, thanks for all the help all is going
well, the last final issue which i have been putting off is on me.
My client conencts great, my server listens great. But ifi try and either
disconnect the client and reconnect without retarting the server nothing
happens. Or if i try two clients the second just gets ignored. Strangely the
second time i try to connect the client when nothing happens i also get no
errors as if the client believes it connected with no issues?
So i am presuming that i have managed to make a server that will only accept
one client? I have no idea why this is. Could it be because i am setting a
global member of _sockWorker to the accept of the listener? I have a feeling
that is my mistake as it appears to me i need to create a new socket worker
each time a client connects and then dispose of this when that client
disconnects. Do you think i am right? Anyway let me know your views.
I have one listener socket set up with a backlog of 4 set, the code for
that is here so when yuo click the listen button this executes:
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 );
}
}
My server connect code is here:
public void OnClientConnect(IAsyncResult asyn)
{
try
{
_socWorker = _socListener.EndAccept (asyn);
Console.WriteLine("{0} Connected",_socWorker.RemoteEndPoint.ToString());
WaitForData(_socWorker);
}
catch(ObjectDisposedException)
{
System.Diagnostics.Debugger.Log(0,"1","\n OnClientConnection: Socket has
been closed\n");
}
catch(SocketException se)
{
MessageBox.Show ( se.Message );
}
}
--
Dan
.
- Follow-Ups:
- Prev by Date: Re: use IOCTL_NDISUIO_SET_OID_VALUE return a error code 31?
- Next by Date: Re: Why can't more than one connect at one time?
- Previous by thread: Re: Layered Service Provider incompatibilities
- Next by thread: Re: Why can't more than one connect at one time?
- Index(es):