如何在python中连接到持久性TCP SOCKET,然后发送和接收数据

时间:2018-10-05 02:07:58

标签: python tcpclient

下面是我用来连接到python中的TCP套接字的代码,问题是我不知道将sock.send(input())放在哪里,这样我就可以基于问的问题。发送的某些数据将需要为int,binary或hex。任何帮助将不胜感激。

from socket import socket;
import re

def readlines(sock, recv_buffer=4096, delim='\n'):
    buffer = ''
    data = True
    while data:
        data = sock.recv(recv_buffer)
        buffer += data
        while buffer.find(delim) != -1:
            line, buffer = buffer.split('\n', 1)
            yield line
    return

def main():
    sock = socket()
    sock.connect( ('172.30.64.211', 1392) )
    for line in readlines(sock):
        print line

if __name__ == '__main__':
    main()

0 个答案:

没有答案