-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathudschatclient.py
executable file
·41 lines (31 loc) · 997 Bytes
/
udschatclient.py
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
#!/usr/bin/env python
import sys
import time
import asyncore, socket
class Client(asyncore.dispatcher):
def __init__(self, sockname):
asyncore.dispatcher.__init__(self)
self.create_socket(socket.AF_UNIX, socket.SOCK_STREAM)
self.connect(sockname)
print "Client Start..."
def handle_close(self):
print "Client: Connection Closed"
self.close()
def handle_read(self):
data = self.recv(1024)
if data:
print "Received ", data
class CmdlineClient(asyncore.file_dispatcher):
def __init__(self, sender, file):
asyncore.file_dispatcher.__init__(self, file)
self.sender = sender
def handle_read(self):
data = self.recv(1024)
self.sender.send(data)
if __name__ == "__main__":
if len(sys.argv) != 2:
print "Usage: %s <socketname>" % sys.argv[0]
sys.exit(1)
sender = Client(sys.argv[1])
cmdline = CmdlineClient(sender, sys.stdin)
asyncore.loop()