blob: 5b3fde6bc2f41da96739383f757e208e3588d063 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
import socket
import sys
from struct import *
HOST, PORT = "localhost", 9999
data = ""
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
#data = pack("!B", 0)
#data += "hello"
#data += "\0"
#data += "world"
data = pack("!BLL", 1, 1234, 5678)
data += "hello, world!"
#data = pack("!BLdd", 2, 1234, 123.123, 12323.23222)
print data
try:
sock.connect((HOST, PORT))
sock.sendall(data)
sock.shutdown(socket.SHUT_WR)
received = sock.recv(1024)
finally:
sock.close()
print "Sent: {}".format(data)
print "Received: {}".format(received[0])
|