Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from socket import *
- s = socket(AF_INET, SOCK_STREAM)
- s.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
- s.bind(('', 8888))
- s.listen(1)
- string = ''
- def encode(string):
- return string.encode()
- while True:
- print('Waiting for connection...')
- clientConn, addr = s.accept()
- print('Connection received from ', addr)
- clientConn.sendall(encode('Welcome to my client server.\nPlease type a word: '))
- while True:
- message = clientConn.recv(1024).rstrip()
- string = string+message
- print(string)
- if(message == 'quit'):
- clientConn.close()
- continue
- elif(message == 'help'):
- clientConn.send(encode('Type a word and press enter or quit to leave\r\n'))
- print ('Here is what you typed: ', message, '\r\n')
- clientConn.send(encode('Here is what you typed: %s\r\n'%message))
- clientConn.close()
- s.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement