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.
123456789101112131415 |
- import socket
-
- s = socket.socket() # instantiate
- host = socket.gethostname() # as both code is running on same pc
- port = 12345 # socket server port number
-
- s.connect((host, port)) # connect to the server
- message = input(" -> ") # take input
-
- while message.strip() != 'STOP':
- s.send(message.encode()) # send message
- data = s.recv(1024).decode() # receive response
- print('Received from server: ' + data) # show in terminal
- message = input(" -> ") # again take input
- s.close() # close the connection
|