import myssn import sys SERVER_ADDRESS = '192.168.100.102' try: client = myssn.client_connect(SERVER_ADDRESS) while True: try: # Send data string_msg = input('$ ') if ':q' in string_msg: break bytes_msg = string_msg.encode() myssn.send(client, bytes_msg) # Look for the response dat = myssn.recv(client) if dat: print('DATA: {!r}'.format(dat)) else: print('INFO: closing socket') myssn.close(sock) break except: print('INFO: Client Exception') break except ConnectionRefusedError: print('INFO: The server is not available') finally:
# myssn_server.py # Based on the server from https://pymotw.com/3/socket/tcp.html import myssn import sys SERVER_ADDRESS = '192.168.0.102' server = myssn.server_create(SERVER_ADDRESS) while True: conn = myssn.server_accept(server) if conn is None: print('INFO: No client connected') else: while True: dat = myssn.recv(conn) if dat is None: print('INFO: Connection closed') break myssn.send(conn, dat) answer = input('INFO: Do you want to try again (y/n)? ') if 'n' in answer: break else: continue print('INFO: Bye!')