Untitled
unknown
plain_text
3 years ago
1.5 kB
7
Indexable
client.py
import socket
def client_program():
#s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
#connet socket
port = 9999 # socket server port number
ip='127.0.0.1'
client_socket = socket.socket() # instantiate
client_socket.connect((ip, port)) # connect to the server
message = input(" -> ") # take input
while message.lower().strip() != 'bye':
client_socket.send(message.encode()) # send message
data = client_socket.recv(1024).decode() # receive response
print('Received from server: ' + data) # show in terminal
message = input(" -> ") # again take input
client_socket.close() # close the connection
if __name__ == '__main__':
client_program()
server.py
import socket
def client_program():
#s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
#connet socket
port = 9999 # socket server port number
ip='127.0.0.1'
client_socket = socket.socket() # instantiate
client_socket.connect((ip, port)) # connect to the server
message = input(" -> ") # take input
while message.lower().strip() != 'bye':
client_socket.send(message.encode()) # send message
data = client_socket.recv(1024).decode() # receive response
print('Received from server: ' + data) # show in terminal
message = input(" -> ") # again take input
client_socket.close() # close the connection
if __name__ == '__main__':
client_program()Editor is loading...