【发布时间】:2018-02-10 09:34:17
【问题描述】:
我正在开发一个使用 UDP/IP 通信相互发送数据的应用程序。但现在它正在使用广播。
private void InitializeSender()
{
sendingClient = new UdpClient();
sendingClient = new UdpClient(broadcastAddr, port);
sendingClient.EnableBroadcast = true;
}
public void Sender(string message)
{
if (!string.IsNullOrEmpty(message))
{
string toSend = yourUsername+":"+message;
byte[] data = Encoding.ASCII.GetBytes(toSend);
sendingClient.Send(data, data.Length);
}
}
我想将其切换为专用发送。我有一个List<Dictionary<string, IPEndPoint>> user_ip = new List<Dictionary<string, IPEndPoint>>();,用于存储用户名和 IP 组合。但我不知道如何从其他应用程序获取这些数据。如何将用户名/IP 信息发送到其他客户端。我应该有广播发现或类似的东西吗?你知道有什么好的解决方案吗?
【问题讨论】:
-
你的应用没有使用 TCP/IP,它使用的是 UDP/IP...
-
是的,只是打错字了
标签: c# networking udpclient