taufiqsobari

PythonSocket

Apr 30th, 2017
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.80 KB | None | 0 0
  1. #Mengirim pesan hello dari client
  2.  
  3. #UpdateCodeServer
  4. #Hapus rule server dan client: iptables -F
  5.  
  6. import socket
  7.  
  8. serversocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  9. #serversocket.bind(('0.0.0.0', 8000))
  10. serversocket.bind(('localhostserver', 8000))
  11. serversocket.listen(5)
  12.  
  13. while True:
  14.     connection, address = serversocket.accept()
  15.     buf =connection.recv(64)
  16.     if len(buf)> 0:
  17.         print buf
  18.         break
  19.  
  20. #UpdateCodeClient
  21. import socket
  22.  
  23. clientsocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  24. #clientsocket.connect(('localhostclient', 8000)) --> socket.error: [Errno 111] Connection refused
  25. clientsocket.connect(('localhostserver', 8000))
  26. #clientsocket.connect('hello') --> TypeError: getsockaddrarg: AF_INET address must be tuple, not str
  27. clientsocket.send('hello')
Add Comment
Please, Sign In to add comment