Recieve data twice over Python TCP Socket -
i'm trying utilize python script sends , receives info server. first, client receives welcome message , asked input server. client should should send prepared response , when finished save servers response. boils downwards (client side) receive, send, receive.
the function i've written this:
s = socket.socket(socket.af_inet, socket.sock_stream) s.connect((tcp_ip, tcp_port)) info = s.recv(buffer_size) s.send(message) data2 = s.recv(buffer_size) s.close() print "received data:", info print "received data2:", data2
yet when programme runs response data, not data2.
is there way receive, send, , receive again?
edit: server code-
self.request.send("what name? ") info = self.request.recv(4096).strip('\n') self.request.send('welcome' + data) self.request.close()
the server code works fine in netcat, i'm trying interact in python now
update: solutions = socket.socket(socket.af_inet, socket.sock_stream) s.connect((tcp_ip, tcp_port)) s.send(message) info = s.recv(buffer_size) data2 = s.recv(buffer_size) s.close() print "received data:", info print "received data:", data2
data2 didn't print because called .send() once... there nil left in buffer send or receive time have sec .recv() call.
python sockets tcp
No comments:
Post a Comment