- 在线时间
- 479 小时
- 最后登录
- 2026-4-17
- 注册时间
- 2023-7-11
- 听众数
- 4
- 收听数
- 0
- 能力
- 0 分
- 体力
- 7790 点
- 威望
- 0 点
- 阅读权限
- 255
- 积分
- 2923
- 相册
- 0
- 日志
- 0
- 记录
- 0
- 帖子
- 1171
- 主题
- 1186
- 精华
- 0
- 分享
- 0
- 好友
- 1
该用户从未签到
 |
# -*- coding: utf-8 -*-, h0 W0 f' x# ~" A
import socket
' ?% V- T) C. ?2 s+ xfrom myutil import *3 X8 l6 F. g1 N9 a8 K: j
from binascii import unhexlify as unhex4 D8 Y2 v+ P/ `& ^
from ctypes import *- J+ _5 e' x3 v. X0 e4 g6 g
dll = cdll.LoadLibrary('mydll.dll')
$ V9 W' k1 J: rprint 'begin load mydll..'$ G! n F0 R; W* c5 K" q4 F: y
HOST, PORT = "192.168.51.28", 5800
, r* h( F% o( p: z4 a; p( c) ?sd ="1234567812345678"* l! u: h g& A0 }
# Create a socket (SOCK_STREAM means a TCP socket)
. }8 \% g2 I. a' K' n7 `sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
5 i/ Y5 b1 [; e4 k2 _7 Dtry:& p: U0 ]* t* \* y! [2 [7 W' h
# Connect to server and send data# }/ S- P, I B2 u
sock.connect((HOST, int(PORT))
4 g" Z8 T( \. b: C6 t" {% D6 j' l2 l print "Sent1 OK:"
& m- {/ s3 ]& F, W' M$ n print sd; a0 p) v) y& o8 q& h- [
# Receive data from the server and shut down; X/ W, H) @# Z6 R' K/ w3 M
received = sock.recv(1024)
0 Q3 g7 X$ Z" A8 |( B print "Received:"
2 p) E2 Y0 Y8 @( ^% C# k print_hex(received)
3 N- p8 t2 v7 M2 V print 'received len is 0x%02x' %(len(received)). [6 X. f' @8 \- }+ v& N
print 'received data analysis...'7 r" z4 e! d V9 [) m
re1=received[0:4]
# e& K- i# o. H9 ~2 o& y print_hex(re1)
) e2 s! _5 ~4 F7 }% [ re1=received[4:6]
. q7 x% W+ }; E9 H0 [; Q print_hex(re1)
" w% J. b# M6 h% ~) a$ h" x A re1=received[6:10]9 t$ x, n( ?' Y, N
print_hex(re1)& [; I0 g, {! n( p3 X
re1=received[10:16]' p3 d8 z- o/ k' K; f! [) L
print_hex(re1)/ P6 D% d3 U( n0 E
0 g0 D& E% V9 o' d6 I3 ^# J #pack2 send+ V, c( R! w6 P4 e
sock.send(sd2.decode('hex'))' d l8 z. c4 I- X
print "Sent2 OK:"
+ m: A& L+ O$ V: o1 N print sd20 `$ g3 h( T! ~9 p
# Receive data from the server and shut down) R7 t, l; J% t5 S1 Q w
received1 = sock.recv(1024)
( E9 v: v, [! e9 R+ U q print "Received1:"
3 I- p8 K3 ~* r# A: K9 m print_hex(received1)
) m$ l6 I2 E7 ? print 'received1 len is 0x%02x' %(len(received1))
. V$ @3 n: l K1 Z1 y! \& l/ b1 m& c
8 A8 G# f# K5 u4 R. Afinally:2 e2 q/ G+ D" V V0 Y! I2 Y
sock.close()
# C+ k2 e! A( l
7 e4 c8 @, t. b* V: I% is=raw_input('press any key to continue...')2 f% V$ @( O, B4 Z3 B" N' G w
* P( @+ X1 s0 y* W1 [8 r
& l) p0 n4 h8 g |
zan
|