Re: Why can't more than one connect at one time?
- From: "Dan" <dvazanias@xxxxxxx>
- Date: Thu, 9 Feb 2006 10:35:12 -0000
Sorry following on from that i do create a new memory area for each socket
in my waitfordata method so i doubt my theory for my prob is right, code
below. So still very stuck:
public void WaitForData(System.Net.Sockets.Socket soc)
{
try
{
if ( pfnWorkerCallBack == null )
{
pfnWorkerCallBack = new AsyncCallback (OnDataReceived);
}
CSocketPacket theSocPkt = new CSocketPacket ();
theSocPkt.thisSocket = soc;
// now start to listen for any data...
soc.BeginReceive (theSocPkt.dataBuffer ,0,theSocPkt.dataBuffer.Length
,SocketFlags.None,pfnWorkerCallBack,theSocPkt);
}
catch(SocketException se)
{
MessageBox.Show (se.Message );
}
}
--
Dan
"Dan" <dvazanias@xxxxxxx> wrote in message
news:%23qx1$PWLGHA.3260@xxxxxxxxxxxxxxxxxxxxxxx
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:
- Re: Why can't more than one connect at one time?
- From: Arkady Frenkel
- Re: Why can't more than one connect at one time?
- References:
- Prev by Date: Why can't more than one connect at one time?
- Next by Date: Re: Why can't more than one connect at one time?
- Previous by thread: Why can't more than one connect at one time?
- Next by thread: Re: Why can't more than one connect at one time?
- Index(es):