简体   繁体   中英

Simple Python TCP IP script but won't return data

ea

Now it is working. The P shows the answer is ok

import socket    # used for TCP/IP communication 


# Prepare for transmission
TCP_IP = 'ip.com'
TCP_PORT = 10000
BUFFER_SIZE = 1024

#Log in as user "test" password "test" and run "/stats"
MESSAGE = '\r\n'


# Open socket, send message, close socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((TCP_IP, TCP_PORT))
print "Connected\n"
s.send(MESSAGE)
print "Message Sent\n"
data = s.recv(BUFFER_SIZE)
print "Data Recvd:\n"
print data
#ADDED THESE LINES AS WELL
s.send("test\r\n")
data = s.recv(BUFFER_SIZE)
print "Data Recvd:\n"
print data
s.close()
print "Socket closed"

Should guide you enough to do the rest yourself. Just send the data in seperate chunks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM