下面是我用来连接到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()