I feel this is a very basic question, but my google-fu is not yielding any specific hits. My problem is related to socket communication differences between windows and unix tcp clients. If i serve up the very basic tcp server code below, and establish a connection via bsd/macos/linux via telnet or netcat (eg telnet remotehost 9997), i am able to enter a line of text, followed by a new-line (\r\n), and the server responds.
When i establish a connection from a windows XP client, via the telnet application (or putty using telnet), i am able to connect, but can only type a single character before the service returns the response. I realize the windows vs unix network stacks handle sockets differently, but the odd bit is, that from my packet capture, i do not see the windows client adding a carriage return .
sample code :
import SocketServer as socketserver
class MyTCPHandler(socketserver.BaseRequestHandler):
def handle(self):
self.request.send("Welcome\r\n")
self.data = self.request.recv(1024).strip()
print("%s wrote:" % self.client_address[0])
print(self.data)
self.request.send(self.data.upper())
if __name__ == "__main__":
server = socketserver.TCPServer(('', 9997), MyTCPHandler)
server.serve_forever()
Here is a packet capture on the server side when connecting from a windows client. 0x62 (b) is the character i typed, during my attempt to type : blah
0000 00 00 00 01 00 06 00 23 33 74 d5 3f 00 00 08 00 .......# 3t.?....
0010 45 00 00 35 77 86 40 00 3c 06 02 5a 0a 0e 14 29 E..5w.@. <..Z...)
0020 0a 03 9c a9 c6 0e 27 0d 20 ed 36 de 87 f2 30 a2 ......'. .6...0.
0030 80 18 ff ff 48 ee 00 00 01 01 08 0a 08 00 46 01 ....H... ......F.
0040 94 f6 26 6f 62 ..&ob
The server responds with 0x42 (B)
0000 00 04 00 01 00 06 00 50 56 86 1a 4e 00 00 08 00 .......P V..N....
0010 45 00 00 35 16 fd 40 00 40 06 5e e3 0a 03 9c a9 E..5..@. @.^.....
0020 0a 0e 14 29 27 0d c6 0e 87 f2 30 a2 20 ed 36 df ...)'... ..0. .6.
0030 80 18 00 b5 c5 0a 00 00 01 01 08 0a 94 f6 29 a0 ........ ......).
0040 08 00 46 01 42 ..F.B
Here is the packet dump from a unix client (netcat remotehost 9997), i enter the letter t (0x74), and and required to forcefully hit the carriage return which generates the 0x0d0a.
0000 00 00 00 01 00 06 00 23 33 74 d5 3f 00 00 08 00 .......# 3t.?....
0010 45 00 00 37 ee d2 40 00 3c 06 8b 0b 0a 0e 14 29 E..7..@. <......)
0020 0a 03 9c a9 c6 10 27 0d 69 ac 8e d6 b8 7b 92 b4 ......'. i....{..
0030 80 18 ff ff c4 b1 00 00 01 01 08 0a 08 00 48 1d ........ ......H.
0040 94 f6 59 2b 74 0d 0a ..Y+t..
So my question is, how can i get this socket server to work with windows clients? Or what do i change in the windows environment, that will allow me to pass a string of characters.