我可以在网络上播放但是排除自己吗?

时间:2014-10-30 18:31:24

标签: c# broadcast server

我正在使用C#创建客户端 - 服务器网络。我成功创建了客户端,但我遇到了服务器问题。当我向服务器广播消息时,它也应该将其发送给其他客户端。问题是服务器也获取消息,然后它认为它是另一条消息,它创建了一个无限循环,一遍又一遍地发送相同的消息。我可以广播除服务器吗?

public void serverThread()
{
    while (true)
    {
        IPEndPoint RemoteIpEndPoint = new IPEndPoint(IPAddress.Any, 0);
        Byte[] receiveBytes = udpClient_rec.Receive(ref RemoteIpEndPoint);
        string returnData = Encoding.ASCII.GetString(receiveBytes);
        if (returnData.StartsWith("broad"))
        {
            UdpClient udpClient_send = new UdpClient();
            IPEndPoint RemoteIpEndPoint1 = new IPEndPoint(IPAddress.Broadcast, 8400);  
            //can i use something else here instead of broadcast to send it to everyone except myself(server)?
            udpClient_send.EnableBroadcast = true;
            udpClient_send.Send(receiveBytes, receiveBytes.Length, RemoteIpEndPoint1);
            udpClient_send.Close();
        }
        this.SetText(RemoteIpEndPoint.Address.ToString() + ": " + returnData.ToString());
        this.SetText2(RemoteIpEndPoint.Address.ToString());
    }
}

0 个答案:

没有答案