Golden Horn Related blog post. Silver Corner Related blog post.
- Large files are sent with Socket.send, without socket.sendall.
- In Python3, the socket must be byte each time it is sent.
- Client Example:
Import= ('127.0.0.1', 9999= socket.socket () sk.connect (ip_ Port) Sk.sendall (bytes (' request to occupy the earth ','UTF8 ' = Sk.recv (1024x768)print(str (server_reply,'UTF8') ) Sk.close ()
- Server-side Example:
ImportSocketip_port= ('127.0.0.1', 9999) SK=Socket.socket () sk.bind (Ip_port) Sk.listen (5) whileTrue:Print('Server Waiting ...') conn,addr=sk.accept () client_data= CONN.RECV (1024) Print(Str (Client_data,'UTF8')) Conn.sendall (bytes ('Don't answer, don't answer , don't answer','UTF8')) whileTrue:client_data= CONN.RECV (1024) if notClient_data.decode (): Break Print(Str (Client_data,'UTF8') ) conn.send (client_data) conn.close ()
Python Socket Usage