Python多进程问题的报错问题
Python多进程问题的报错问题想通过多进程实现客户端给服务器发送信息,服务器同时接收多个信息。但是会收到以下报错:
OSError: 通常每个套接字地址(协议/网络地址/端口)只允许使用一次。
看网上说是进程停止又重启造成的结果
贴下自己的代码,麻烦大家看下
<p>import multiprocessing
from socket import
import time</p><p>server_name='172.20.53.211'
port_number1=12002
port_number2=12003</p><p><p>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)</p><p>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)</p><p>
p1=multiprocessing.Process(target=process_one())
p1.start()
p2=multiprocessing.Process(target=process_two())
p2.start()</p><p>以上是服务器端的代码</p><p>以下是客户端发送代码</p><p>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()</p>
求大佬指出哪里错了,谢谢
参考下这个链接https://ask.csdn.net/questions/1008246 multiprocessing.Process 写错了 线程使用是否正确 target=函数加的话,不要加(),就用调用start()方法 端口检查下
页:
[1]