1 | #!/usr/bin/env python
|
---|
2 |
|
---|
3 | import socket
|
---|
4 | import struct
|
---|
5 |
|
---|
6 | TCP_IP = '10.10.0.51'
|
---|
7 | TCP_PORT = 5123
|
---|
8 | BUFFER_SIZE = 1024
|
---|
9 | MESSAGE = struct.pack('!l',BUFFER_SIZE)
|
---|
10 |
|
---|
11 | s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
---|
12 | s.connect((TCP_IP, TCP_PORT))
|
---|
13 | r = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
---|
14 | r.connect((TCP_IP, TCP_PORT+2))
|
---|
15 | print "Requesting ",BUFFER_SIZE, " bytes"
|
---|
16 |
|
---|
17 | for 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)
|
---|
25 | s.close()
|
---|
26 | r.close()
|
---|