How to use Socket address more than once on windows
this same question has been asked several times, and most answers where related to TCP/IP
. But im looking for Bluetooth
related.
Im trying to send information between 2 machines through bluetooth. I installed pybluez
on both linux and windows, It worked fine on discovering other nearby devices on both Os. Later i used this code as an example to send information. It worked fine when, client was linux machine and server was linux machine. When i run the server side code on windows7 i got the error
server_sock.bind(("",port))
File "C:Python27libsite-packagesbluetoothmsbt.py", line 60, in bind
status = bt.bind (self._sockfd, addr, port)
IOError: Only one usage of each socket address (protocol/network address/port) is normally permitted.
which i realized that on windows once the port is used, just closing the address/port is not sufficient but also has to be set to reuse(from SO). But there is no similar library inside bluetooth.BluetoothSocket
to reuse the address/port.
How can i use a socket more than once? or is there an alternative way,..?
Code:
import bluetooth
server_sock=bluetooth.BluetoothSocket( bluetooth.RFCOMM )
port = 1
server_sock.bind(("",port))
server_sock.listen(1)
client_sock,address = server_sock.accept()
print "Accepted connection from ",address
data = client_sock.recv(1024)
print "received [%s]" % data
client_sock.close()
server_sock.close()
I experienced the same problem as you but resolved it yesterday and thought maybe you could try the same approach as me. Try using a different port number instead of port 1. I personally used port 5 (instea of 1) and stopped having this issue. Hope it helps! For some reason I am not quite sure about yet, port 1 cannot be re-used after a first successful connection in that port.
重置hciconfig,这是因为套接字已被使用
链接地址: http://www.djcxy.com/p/58318.html