Best way to open a socket in Python

前端 未结 3 1775
难免孤独
难免孤独 2020-12-14 06:07

I want to open a TCP client socket in Python. Do I have to go through all the low-level BSD create-socket-handle / connect-socket stuff or is there a simpler one-line way?

3条回答
  •  不知归路
    2020-12-14 06:12

    OK, this code worked

    s = socket.socket()
    s.connect((ip,port))
    s.send("my request\r")
    print s.recv(256)
    s.close()
    

    It was quite difficult to work that out from the Python socket module documentation. So I'll accept The.Anti.9's answer.

提交回复
热议问题