-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.py
48 lines (36 loc) · 1.14 KB
/
client.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
42
43
44
45
46
47
48
from twisted.internet.protocol import ClientFactory
from twisted.internet import reactor
from twisted.protocols.basic import LineReceiver
from twisted.conch.telnet import TelnetProtocol
from twisted.internet import stdio
class StdinProtocol(LineReceiver):
from os import linesep as delimiter
def __init__(self, network):
self.network = network
def write(self, text):
self.transport.write('\007' + text)
def print_prompt(self):
self.write('#> ')
def connectionMade(self):
self.print_prompt()
def lineReceived(self, line):
self.network.transport.write(line)
self.network.transport.write('\r\n')
self.print_prompt()
class VikiProtocol(LineReceiver, TelnetProtocol):
def connectionMade(self):
self.stdin = StdinProtocol(self)
stdio.StandardIO(self.stdin)
def lineReceived(self, line):
self.stdin.write('\033[2;K' + line + '\r\n\r\n')
self.stdin.print_prompt()
class VikiFactory(ClientFactory):
def buildProtocol(self, addr):
p = VikiProtocol()
p.factory = self
return p
def main():
reactor.connectTCP("localhost", 8123, VikiFactory())
reactor.run()
if __name__ == '__main__':
main()