import socketserver
import struct
from collections import namedtuple
class MyUDPHandler(socketserver.BaseRequestHandler):
def handle(self):
data = self.request[0].strip()
socket = self.request[1]
if len(data) >= 34:
format_ = "6shhih50s2s"
MyStruct = namedtuple("MyStruct", "sMark nPackLen nFlag nGisIp nPort sData sEnd")
tuple_to_send = MyStruct(sMark="\r\n{}".format("*KW").encode("ascii"),
nPackLen=struct.calcsize(format_),
nFlag=0x0002,
nGisIp=0,
nPort=0,
sData= "*KW,AA05954122,015,080756,#".encode("ascii"),
sEnd="\r\n".encode("ascii"))
string_to_send = struct.pack(format_, *tuple_to_send._asdict().values())
socket.sendto(string_to_send, self.client_address)
print('waiting Reply Bytes String from client..') //how to get the reply bytes string from Client side?
if __name__ == "__main__":
HOST, PORT = "", 6903
server = socketserver.UDPServer((HOST, PORT), MyUDPHandler)
server.serve_forever()
Step 1:Server receive GPS device bytes string.and will get a dynamic IP address
Step 2:when server are get the client dynamic IP already,Server will send a command to client side(GPS Device).
Step 3:Client Side will sending back a bytes string,but i have no idea how to capture the reply bytes string on here.
You can do this if server replies to the IP Address and port of the Sender