Advertisement
7heSama

tcp_socket_client_multithreaded.py

Jun 6th, 2022
820
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.60 KB | None | 0 0
  1. # Python TCP Socket Server
  2. from socket import *
  3.  
  4. # Network settings
  5. localhost = gethostbyname("localhost");
  6. tcpPort = 12001;
  7.  
  8. # Create TCP client
  9. clientSocket = socket(AF_INET, SOCK_STREAM);
  10. clientSocket.connect((localhost, tcpPort));
  11.  
  12. # Debug
  13. print("Socket: {}".format(clientSocket));
  14. print("localhost: {}; port: {}".format(localhost, tcpPort));
  15.  
  16. # Send and receive a message
  17. while True:
  18.     msg = input("Please, write a message! ");
  19.     clientSocket.send(msg.encode());
  20.     msgMod = clientSocket.recv(1024);
  21.     print("Response from server: " + msgMod.decode() + "\n");
  22. connSocket.close();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement