本文介绍了C#代码客户端服务器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的客户端&异步通信代码服务器,即多个客户端和单服务器,但是我的问题是,新客户端一加入服务器,服务器就只能发送&接收到来自最近连接的PC的请求,而不是已连接的PC.从消息中组合框中列出了已连接的PC,该消息已发送到选定的PC,但它不起作用...

用于将数据发送到组合框中的选定PC

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


Thanx

推荐答案



这篇关于C#代码客户端服务器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 09:01
查看更多