For a friend.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
672 B

#!/usr/bin/env python3
import socket
from cmd import Cmd
TCP_IP = '127.0.0.1'
TCP_PORT = 5005
BUFFER_SIZE = 1024
MESSAGE = b"Hello, World!"
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((TCP_IP, TCP_PORT))
class MyPrompt(Cmd):
def do_exit(self, inp):
'''exit the application and close remote server.'''
s.send(b"exit")
data = s.recv(BUFFER_SIZE)
print ("received data:", data)
return True
def do_send(self, inp):
'''Send a message'''
s.send(bytes(inp, "utf8"))
print(inp)
data = s.recv(BUFFER_SIZE)
print ("received data:", data)
MyPrompt().cmdloop()
s.close()