blob: d827775b43a3fe9d51fcb7fa889f09783e39cd56 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
import sys
import bluetooth
if len(sys.argv) < 2:
print "usage: l2-unreliable-server"
sys.exit(2)
timeout = int(sys.argv[1])
assert timeout >= 0
server_sock=bluetooth.BluetoothSocket( bluetooth.L2CAP )
server_sock.bind(("",0x1001))
server_sock.listen(1)
while True:
print "waiting for incoming connection"
client_sock,address = server_sock.accept()
print "Accepted connection from %s" % str(address)
print "waiting for data"
total = 0
while True:
try:
data = client_sock.recv(1024)
except bluetooth.BluetoothError, e:
break
if len(data) == 0: break
total += len(data)
print "total byte read: %d" % total
client_sock.close()
print "connection closed"
server_sock.close()
|