hi ,
I am working on a Server-Client Game on which multiple user can play this game. I have implemented this with the TCPListener and thread. but the problem is that connection can't be by more than one user at a time. When one connection is made then other can be made else it go to hung state. Can I implements this with asynchronous server-client techninque. Only Client code is for the user's who play the game . Server only send message to clients. Can Any one help me How can I achieve this problem. If any one have code for this plz send it to me at rathi.0709@gmail.com or post the answer.
public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
clients = new ArrayList();
processor = new Thread(new ThreadStart(StartListening));
processor.Start();
//
// TODO: Add any constructor code after InitializeComponent call
//
}
/
/Function to open socket in Listen mode
private void StartListening()
{
try
{
//listenport = clsGetIpAddress.PortNo ;
//listener = new TcpListener(listenport);
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();
}
}
catch(Exception e)
{
Console.WriteLine(e.ToString() );
}
}
}
catch (SocketException ex)
{
MessageBox.Show(ex.Message );
Regards,
Dinesh Kumar