我使用python osc连接传感器,我想连接传感器10分钟接收消息并关闭服务器。以下是我做的工作代码:
from pythonosc import udp_client
from pythonosc import osc_message_builder
from pythonosc import dispatcher
import socket, threading, time
from pythonosc import osc_server
import time
tstart=time.time();
# Change this to the NGIMU IP address
send_address = '192.100.1.1', 9000
client =udp_client.SimpleUDPClient('192.100.1.1', 9000)
# msg=osc_message_builder.OscMessageBuilder()
# msg=msg.build()
print(str(socket.gethostbyname(socket.gethostname())))
#receive_address='192.100.16.2', 8000
dispatcher = dispatcher.Dispatcher()
server = osc_server.ThreadingOSCUDPServer(('192.100.16.2', 8001),dispatcher)
#server.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
print("Serving on {}".format(server.server_address))
server.server_activate()
#server.server_close()
tnow= time.time();
tdiff= tnow-tstart
while(tdiff*1000<10):
tnow= time.time();
tdiff= tnow-tstart;
print(tdiff)
if(tdiff*1000>10):
server.server_close()`
` 我收到以下错误:
文件&#34;&#34;,第1行,in runfile(&#39; C:/sensor/ngimu.py' ;, wdir =&#39; C:/ sensor /&#39;)
文件&#34; C:\ ProgramData \ Anaconda3 \ lib \ site-packages \ spyder \ utils \ site \ sitecustomize.py&#34;,第705行,在runfile中 execfile(filename,namespace)
文件&#34; C:\ ProgramData \ Anaconda3 \ lib \ site-packages \ spyder \ utils \ site \ sitecustomize.py&#34;,第102行,在execfile中 exec(compile(f.read(),filename,&#39; exec&#39;),命名空间)
文件&#34; C:/sensor/ngimu.py" ;,第27行,in server = osc_server.ThreadingOSCUDPServer((&#39; 192.168.1.2&#39;,8001),调度员)
文件&#34; C:\ ProgramData \ Anaconda3 \ lib \ site-packages \ pythonosc \ osc_server.py&#34;,第107行, init super()。 init (server_address,_UDPHandler)
文件&#34; C:\ ProgramData \ Anaconda3 \ lib \ socketserver.py&#34;,第453行, init self.server_bind()
文件&#34; C:\ ProgramData \ Anaconda3 \ lib \ socketserver.py&#34;,第467行,在server_bind中 self.socket.bind(self.server_address)
OSError:[WinError 10048]通常只允许使用每个套接字地址(协议/网络地址/端口)
如何解决此错误? -swetha