Hi, I have a simple TCP server client in .net and for some reason the
Accept() function in the Server part never gets called and never
returns a new socket. This thing has been driving me nuts for days,
here is the code please help if you can (the two machines that I am
trying to connect are on a LAN Ethernet):
Client()
{
Socket dcspTCPClient = null;
try
{
dcspTCPClient = new Socket
(AddressFamily. InterNetworkSoc ketType.Stream, ProtocolType.Tc p);
IPAddress remoteIPAddress =
(Dns.Resolve(st rHostName)).Add ressList[0];
IPEndPoint serverIPEndPoin t = new
IPEndPoint(remo teIPAddress,nSe rverPort);
EndPoint serverEndPoint = (EndPoint)serve rIPEndPoint;
dcspTCPClient.C onnect(serverEn dPoint);
}
catch (Exception error)
{
string strError = "TCPClient Error: "+error.ToStrin g();
}
}
private Socket m_tcpServer;
server()
{
try
{
IPEndPoint Ipep = new IPEndPoint(IPAd dress.Any, nPortListen);
m_tcpServer = new Socket(AddressF amily.InterNetw ork,
SocketType.Stre am, ProtocolType.Tc p);
m_tcpServer.Bin d(Ipep);
m_tcpServer.Lis ten(nClients);
}
while(true)
{
try
{
Socket sockAcceptClien t = m_tcpServer.Acc ept();
if(sockAcceptCl ient.Connected)
{
ThreadPool.Queu eUserWorkItem(n ew
WaitCallback(tc pMServerReceive Send), sockAcceptClien t);
}
}
catch(SocketExc eption se)
{
string strSocketExepti on = se.ToString();
}
}
}
catch (SocketExceptio n se)
{
string strSock = "createTCPServe rMultithread error:
"+se.ToString() ;
}
}
It looks like it is connecting fine but Accept never gets called on
the server side.
Accept() function in the Server part never gets called and never
returns a new socket. This thing has been driving me nuts for days,
here is the code please help if you can (the two machines that I am
trying to connect are on a LAN Ethernet):
Client()
{
Socket dcspTCPClient = null;
try
{
dcspTCPClient = new Socket
(AddressFamily. InterNetworkSoc ketType.Stream, ProtocolType.Tc p);
IPAddress remoteIPAddress =
(Dns.Resolve(st rHostName)).Add ressList[0];
IPEndPoint serverIPEndPoin t = new
IPEndPoint(remo teIPAddress,nSe rverPort);
EndPoint serverEndPoint = (EndPoint)serve rIPEndPoint;
dcspTCPClient.C onnect(serverEn dPoint);
}
catch (Exception error)
{
string strError = "TCPClient Error: "+error.ToStrin g();
}
}
private Socket m_tcpServer;
server()
{
try
{
IPEndPoint Ipep = new IPEndPoint(IPAd dress.Any, nPortListen);
m_tcpServer = new Socket(AddressF amily.InterNetw ork,
SocketType.Stre am, ProtocolType.Tc p);
m_tcpServer.Bin d(Ipep);
m_tcpServer.Lis ten(nClients);
}
while(true)
{
try
{
Socket sockAcceptClien t = m_tcpServer.Acc ept();
if(sockAcceptCl ient.Connected)
{
ThreadPool.Queu eUserWorkItem(n ew
WaitCallback(tc pMServerReceive Send), sockAcceptClien t);
}
}
catch(SocketExc eption se)
{
string strSocketExepti on = se.ToString();
}
}
}
catch (SocketExceptio n se)
{
string strSock = "createTCPServe rMultithread error:
"+se.ToString() ;
}
}
It looks like it is connecting fine but Accept never gets called on
the server side.