Advertisement
Guest User

SERVER

a guest
Mar 23rd, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.77 KB | None | 0 0
  1. import socket
  2. import sys
  3.  
  4. # Create a TCP/IP socket
  5. sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  6.  
  7. # Bind the socket to the port
  8. server_address = ('localhost', 10000)
  9. print('starting up on {} port {}'.format(*server_address))
  10. sock.bind(server_address)
  11.  
  12. # Listen for incoming connections
  13. sock.listen(5)
  14.  
  15. while True:
  16.     # Wait for a connection
  17.     print('waiting for a connection')
  18.     connection, client_address = sock.accept()
  19.     try:
  20.         print('connection from', client_address)
  21.  
  22.         # Receive the data in small chunks and retransmit it
  23.         while True:
  24.             data = connection.recv(8)
  25.             if data.decode() == "Conectei":
  26.                 print("Vlw")
  27.  
  28.     finally:
  29.         # Clean up the connection
  30.         connection.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement