# -*- coding: utf-8 -*- ' M! X( f& z R) Rimport socket, s y* L* D1 P: J$ ]: l( M
from myutil import * 5 t# e, n1 {! M2 E7 p: Lfrom binascii import unhexlify as unhex; h6 a9 }) O9 O/ S
from ctypes import * 6 h) E6 w5 ^1 r, ~ Z& Jdll = cdll.LoadLibrary('mydll.dll'), F! v" o# S: g- g' O+ r
print 'begin load mydll..' 0 H& ]6 M* a- {$ `$ oHOST, PORT = "192.168.51.28", 5800 3 u/ } h' k C( h: j# rsd ="1234567812345678"' l6 k0 L- R" d
# Create a socket (SOCK_STREAM means a TCP socket) 3 W5 [5 p8 O# @( o" n; j5 r# ysock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)2 Q' w0 P, T B% ]$ N2 y
try: 8 F( D9 ?, f8 X; D # Connect to server and send data ! r; ?0 _$ p0 a1 Z, d sock.connect((HOST, int(PORT))4 Z2 _) P+ `) N2 m9 x. L
print "Sent1 OK:" 9 H! v5 S2 c1 [& ^. P8 h$ P print sd z- m( D S2 r% d) v- | ~, z/ E # Receive data from the server and shut down 4 k: }( P+ v: P8 G+ ~6 ]+ X received = sock.recv(1024) 2 y; P8 p" I7 l9 Q8 A9 M& q print "Received:" ' K) J( [, O' g. v print_hex(received) # {$ z3 i# H/ Y* } print 'received len is 0x%02x' %(len(received)) / S5 K9 Y) z L; m* f% o8 u print 'received data analysis...'. P. K% L7 D: E& S, L8 r
re1=received[0:4] - c e f3 t6 [ print_hex(re1)) w# V! ] |: |/ m3 I
re1=received[4:6] 3 p$ @0 T) D" o: I print_hex(re1)' ^" L: W: o/ g2 \+ K. B6 S
re1=received[6:10] / Q; w$ B+ e+ t, w+ a# N print_hex(re1) 3 E- v4 Z9 O( @8 n- n) m' q, O re1=received[10:16] $ Z! S/ U5 l* u print_hex(re1)& d; V( {& C+ F/ V4 g
" \$ R+ F& K. d* E1 J4 R( F #pack2 send8 f+ ] S% S/ U2 @
sock.send(sd2.decode('hex'))' f y" M% {6 J& q# `, u
print "Sent2 OK:"& {# {7 M0 V: P" E
print sd2 ) h; M- `' @: }, }& h5 v # Receive data from the server and shut down ' F/ q6 a4 } e8 H received1 = sock.recv(1024) . T% r. K# Y3 ]8 j x( j3 D( ]7 K print "Received1:"6 f' c. u! p$ T! E( Y0 E
print_hex(received1) 4 Q! _* M; w! N* R print 'received1 len is 0x%02x' %(len(received1)) 0 h0 I# P, ^6 Z. i) g' ], t8 j7 p( s* c) C; A; J- W
finally:8 r/ @* @0 ]: i
sock.close() 9 @5 F2 n& o8 e' u1 Z m0 f& I8 h ) M1 W# e0 ?6 ?s=raw_input('press any key to continue...') 2 g" J+ w2 q l' ^ R' }5 {' u5 b1 R! k# f- r5 E- b5 p