Package logilab-common-0 ::
Package 36 ::
Package 1 ::
Module monclient
|
|
1 """Simple interpreter client for monserver provides a simple readline interface.
2
3 :copyright: 2000-2008 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
4 :contact: http://www.logilab.fr/ -- mailto:contact@logilab.fr
5 :license: General Public License version 2 - http://www.gnu.org/licenses
6 """
7 __docformat__ = "restructuredtext en"
8
9 from warnings import warn
10 warn('this module is deprecated and will disappear in a near release',
11 DeprecationWarning, stacklevel=1)
12
13 from socket import socket, SOCK_STREAM, AF_INET
14 from select import select
15 import sys
16 import readline
17 import threading
18
20 """A thread that reads from a socket and output
21 to stdout as data are received"""
23 threading.Thread.__init__(self)
24 self.socket = sock
25 self.stop = False
26
28 """prints socket input indefinitely"""
29 fd = self.socket.fileno()
30 self.socket.setblocking(0)
31 while not self.stop:
32 iwl, _, _ = select([fd], [], [], 2)
33 if fd in iwl:
34 data = self.socket.recv(100)
35 if data:
36 sys.stdout.write(data)
37 sys.stdout.flush()
38
39
40
42 """simple client that just sends input to the server"""
43 sock = socket( AF_INET, SOCK_STREAM )
44 sock.connect( (host, port) )
45 sp_thread = SocketPrinter(sock)
46 sp_thread.start()
47 while 1:
48 try:
49 line = raw_input() + "\n"
50 sock.send( line )
51 except EOFError:
52 print "Bye"
53 break
54 except:
55 sp_thread.stop = True
56 sp_thread.join()
57 raise
58 sp_thread.stop = True
59 sp_thread.join()
60
61
62 if __name__ == "__main__":
63 server_host = sys.argv[1]
64 server_port = int(sys.argv[2])
65 client(server_host, server_port)
66