Internal/PacketServer: client.py

File client.py, 630 bytes (added by nilanjan, 12 years ago)
Line 
1#!/usr/bin/env python
2
3import socket
4import struct
5
6TCP_IP = '10.10.0.51'
7TCP_PORT = 5123
8BUFFER_SIZE = 1024
9MESSAGE = struct.pack('!l',BUFFER_SIZE)
10
11s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
12s.connect((TCP_IP, TCP_PORT))
13r = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
14r.connect((TCP_IP, TCP_PORT+2))
15print "Requesting ",BUFFER_SIZE, " bytes"
16
17for i in range(1,15):
18 s.send(MESSAGE)
19 data = s.recv(BUFFER_SIZE)
20
21 # First 4 bytes are checksum followed by the 4 byte sequence number
22 crc,sn = struct.unpack('!LL',data[:8])
23 print "Seq #:", sn, " with CRC [", hex(crc), "]"
24 r.send(data)
25s.close()
26r.close()