Click here to Skip to main content
15,905,785 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Here is my code for asynchronous communication of client & server i.e multiple clients & single Server but my problem as soon as new client joins the server then server only send & recieve request from that recently connected pc not the pc that are already connected.The Connected Pc's are listed in combobox from the message is send to selected pc but it is not working...

This is use to send data to selected pc in combo box
private void sendData(String data)
{
    IPAddress ipep =IPAddress.Parse(comboBox1.SelectedItem.ToString());
    Socket server = new Socket(AddressFamily.InterNetwork , SocketType.Stream, ProtocolType.Tcp);
    IPEndPoint ipept = new IPEndPoint( ipep, hostPort);
    //TcpClient cl = new TcpClient(ipept.Address.ToString(), hostPort);
    NetworkStream nStream = tcpClient.GetStream();
    ASCIIEncoding asciidata = new ASCIIEncoding();
    byte[] buffer = asciidata.GetBytes(data);
    if (nStream.CanWrite)
    {
        nStream.Write(buffer, 0, buffer.Length);
        nStream.Flush();
    }
}

Thanx
Posted
Updated 5-Apr-11 5:25am
v2

Please see my past Answer to related Question: Multple clients from same port Number[^]. I put a skeleton description of the structure of the application. It can help you too. Further questions are welcome (please do not post the as Answer).

—SA
 
Share this answer
 
Since you didn't post your WCF server code, I would suggest that you google this:

"wcf multiple client connections"

You'll get half a million results back on that. Another possible search phrase is

"WCF multiple concurrent clients"
 
Share this answer
 
Comments
Zeeshan17 5-Apr-11 11:36am    
Thanx for ur reply...
But i m not using WCF i m using TCP can u plz provide ny help
Marc A. Brown 5-Apr-11 11:48am    
I don't have any help to provide you on your question, but I *do* have a bit of friendly advice (seriously). If you insist on speaking in txtspk ("ur, u, plz" instead of "your, you, please"), expect on getting badly flamed for it. Folks in these parts are particularly opposed to that kind of shorthand.
Good luck with your question!
Sergey Alexandrovich Kryukov 5-Apr-11 17:04pm    
Marc, you're absolutely right. I hope the inconvenience in reading this and the irritation (which I happen to share) is quite explainable.
Thank you for this note.
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900