Advertisement
Guest User

TCP socket

a guest
Jul 15th, 2018
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.56 KB | None | 0 0
  1. import socket
  2.  
  3. #SERVER = server side code
  4. #CLIENT = client side code
  5. server_address = ('ip', int(port))
  6. tcp = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  7. #tcp.connect(server_address) #CLIENT
  8. tcp.bind(server_address)#SERVER
  9.  
  10. try:
  11.     tcp.listen(1) #SERVER
  12.     connection, client = tcp.accept() #SERVER
  13.     print(connection, client) #SERVER
  14.     connection.send("hello World") #SERVER
  15.     recieved = ""
  16.     while recieved == "":
  17.         recieved = connectioin.recv() #SERVER
  18.         #recieved = tcp.recv() #CLIENT
  19.     print(recieved)
  20. except KeyboardInterrupt:
  21.     print("quitting")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement