Advertisement
Guest User

Untitled

a guest
Nov 14th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. #!/usr/bin/python3
  2.  
  3. import socket
  4.  
  5. #Creating the socket object
  6. serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  7.  
  8. host = socket.gethostname() #Host is the server IP
  9. port = 444 #Port to listen on
  10.  
  11. #Binding to socket
  12. serversocket.bind((host, port)) #Host will be replaced/substitued with IP, if changed and not running on host
  13.  
  14. #Starting TCP listener
  15. serversocket.listen(3)
  16.  
  17. while True:
  18. #Starting the connection
  19. clientsocket,address = serversocket.accept()
  20.  
  21. print("received connection from " % str(address))
  22.  
  23. #Message sent to client after successful connection
  24. message = 'hello! Thank you for connecting to the server' + "\r\n"
  25.  
  26. clientsocket.send(message)
  27.  
  28. clientsocket.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement