小弟想通过多进程实现客户端给服务器发送信息,服务器同时接收多个信息。但是会收到以下报错:
OSError: [WinError 10048] 通常每个套接字地址(协议/网络地址/端口)只允许使用一次。
看网上说是进程停止又重启造成的结果
小弟贴下自己的代码,麻烦大家看下
import multiprocessing
from socket import
import time
server_name='172.20.53.211'
port_number1=12002
port_number2=12003
def process_one():
server_socket1 = socket(AF_INET, SOCK_DGRAM)
server_socket1.bind(('', port_number1))
data_receive1, client_address = server_socket1.recvfrom(1024)
server_socket1.close()
print(data_receive1,1)
def process_two():
server_socket2 = socket(AF_INET, SOCK_DGRAM)
server_socket2.bind(('', port_number2))
data_receive2, client_address = server_socket2.recvfrom(1024)
server_socket2.close()
print(data_receive2,2)
p1=multiprocessing.Process(target=process_one())
p1.start()
p2=multiprocessing.Process(target=process_two())
p2.start()
以上是服务器端的代码
以下是客户端发送代码
from socket import *
import time
server_name='172.20.53.211'
port_number1=12002
port_number2=12003
client_socket = socket(AF_INET, SOCK_DGRAM)
f1=open('1.txt','rb')
fcontent=f1.read()
client_socket.sendto(fcontent,(server_name, port_number1))
time.sleep(0.2)
client_socket.sendto('a'.encode('UTF-8'),(server_name, port_number2))
client_socket.close()
求大佬指出哪里错了,谢谢