想要 SOCKET 向 多个IP发送消息的代码 或具体方法

lovepei531 2008-09-11 07:10:01
public void speaks()
{
Socket listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
listener.Bind(new IPEndPoint(IPAddress.Any, 2112));
listener.Listen(1);
string ip;
byte[] receivedBytes = new byte[1024];
while (true)
{
Socket socket = listener.Accept();
string receivedvalue = string.Empty;
string[] ips = (socket.RemoteEndPoint.ToString()).Split(spliti);
ip=ips[0];
while (true)
{
int numbytes = socket.Receive(receivedBytes);
receivedvalue += Encoding.UTF8.GetString(receivedBytes, 0, numbytes);
break;
}
//Console.WriteLine(, ip[0], receivedvalue);
Invoke(new adddelegage(add), ip+"\t说:" + receivedvalue,ip);//用委托向文本写入消息
byte[] replymessage = Encoding.UTF8.GetBytes(ip + "\t说:" + receivedvalue);
socket.Send(replymessage);
socket.Shutdown(SocketShutdown.Both);
{
socket.Close();
}
}
}


上面是我的代码,大家帮我完成下啊,谢谢大家了啊
...全文
77 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
cpio 2008-10-07
  • 打赏
  • 举报
回复
可是你加的break是加在while(true)里面,这样的话,while(true)还有什么用呢
lovepei531 2008-09-11
  • 打赏
  • 举报
回复
???不加BREAK 怎么能跳出循环, 发送信息啊
cpio 2008-09-11
  • 打赏
  • 举报
回复
没搞明白你的代码什么意思,while(true)里面加个break,要干嘛啊?

111,094

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧