-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathServerClientClass
57 lines (41 loc) · 1.78 KB
/
ServerClientClass
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
import bluetooth
import sys
import multiprocessing
#THIS CODE IS IN PROGRESS.NOT FUNCTIONAL AS OF NOW
class Server(object):
def __init__(self):
self.server_sock=bluetooth.BluetoothSocket( bluetooth.RFCOMM )
self.port = 0
def start(self):
self.server_sock.bind(("",self.port))
self.server_sock.listen(1)
print "listening on port %d" % port
uuid = "1e0ca4ea-299d-4335-93eb-27fcfe7fa848"
bluetooth.advertise_service(self.server_sock, "FooBar Service", uuid )
self.client_sock,address = self.server_sock.accept()
print "Accepted connection from ",address
data = client_sock.recv(1024)
print "recieved [%s]" % data
def end(self):
self.client_sock.close()
self.server_sock.close()
class client(object):
def __init__(self):
uuid = "1e0ca4ea-299d-4335-93eb-27fcfe7fa848"
self.service_matches = bluetooth.find_service( uuid = uuid )
if len(service_matches) == 0:
print "couldn't find the FooBar service"
sys.exit(0)
first_match = self.service_matches[0]
port = first_match["port"]
name = first_match["name"]
host = first_match["host"]
print "connecting to \"%s\" on %s" % (name, host)
self.sock=bluetooth.BluetoothSocket( bluetooth.RFCOMM )
self.sock.connect((host, port))
self.sock.send("hello!!")
self.sock.close()
if __name__ =="__main__":
server = Server()
client =client()
multiprocess(server,client)