Multiple Client Connection Simultaneously

I am working on Server client online game on which multiple player can play. But the problem is that
connection can me made one at a time. If we make more than one connection simultaneouly then game will
hung. I Have implement this with the tcplistener . Can I implements this with asynchronouly. If yes then
how can I achive multiple connection and receive and send message from the clients.

my server code is :


public ServerForm()
{
processor = new Thread(new ThreadStart(StartListening));
processor.Start();

}
listener = new TcpListener(clsGetIpAddress.PortNo);
listener.Start();
while (true)
{
try
{
lock(this)
{
Socket s = listener.AcceptSocket() ;
clientsocket = s;
clientservice = new Thread(new ThreadStart(ServiceClient));
clientservice.Start();
}
}


Client Code Is:

public void Connect()
{


EstablishConnection();

if(connected)
{
RegisterWithServer();
receive = new Thread(new ThreadStart(ReceiveChat));
receive.Start();

}
}


private void EstablishConnection()
{

try
{
clientsocket = new TcpClient(serveraddress,serverport);
ns = clientsocket.GetStream();

sr = new StreamReader(ns);
connected = true;

}
Catch{}
}

[1507 byte] By [DineshRathi] at [2007-12-23]

.NET Development

Site Classified