Best way to open a socket in Python

前端 未结 3 1774
难免孤独
难免孤独 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:34

    Opening sockets in python is pretty simple. You really just need something like this:

    import socket
    sock = socket.socket()
    sock.connect((address, port))
    

    and then you can send() and recv() like any other socket

提交回复
热议问题