-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathecho_client_twisted.py
More file actions
38 lines (28 loc) · 950 Bytes
/
echo_client_twisted.py
File metadata and controls
38 lines (28 loc) · 950 Bytes
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
#from twisted.internet import stdio
from twisted.protocols import basic
from twisted.internet import reactor
from twisted.internet import reactor, protocol
# Protocol untuk pengiriman sama penerimaan data dari server
class EchoClient(protocol.Protocol):
def connectionMade(self):
input = raw_input("Masukkan pesan yang akan dikirim : ")
self.transport.write(input)
def dataReceived(self, data):
print "Server said:", data
input = raw_input("Masukkan pesan yang akan dikirim : ")
self.send_message(input)
def send_message(self, input) :
self.transport.write(input)
class EchoFactory(protocol.ClientFactory):
client = None
def buildProtocol(self, addr):
self.client = EchoClient()
return self.client
def main():
factory = EchoFactory()
# Koneksi ke TCP server
reactor.connectTCP("localhost", 8002, factory)
# Koneksi ke console untuk dapatkan input dari keyboard
reactor.run()
if __name__ == '__main__':
main()