【发布时间】:2016-03-31 20:05:41
【问题描述】:
我有多个线程使用多个套接字,但都指向一个端口。它会起作用吗?我看到一些线程说多个应用程序不能使用相同的端口,但我不确定它是否直接解决了这个问题
代码示例
static IPEndPoint b = new IPEndPoint(IPADRESS, PORT);
static Thread listenThread = new Thread(listen);
static Thread sendThread = new Thread(send);
static void listen(){
Socket socket = new Socket;
socket.bind(b);
while(exit == false){
Socket.listen(10);
//handle Data
}
static void send(){
Socket socket = new Socket;
socket.bind(b);
while(exit == false){
Socket.send(msg)
}
【问题讨论】:
-
这是一个很好的答案,总结了一切:stackoverflow.com/a/724022/24472
标签: c# multithreading sockets