Hey,
Im using python3, i have a script on the server that gets UDP requests from client and then
the server translate thous requests to tcp and transfer them internally to a py script on the server.
My question is :
My tcp_to_udp script on the server knows that the first request is always the headers and then the data.
How do i make my script know the difference between headers and data ?
I want my script to know what is data and what is headers because now it only
knows that first request is headers but this method is not so good if connection restarts..
Also if its multi connection, to know which headers is connected to which data.
my script now (on the server):
data type :
headers are json type converted to bytes:
Im using python3, i have a script on the server that gets UDP requests from client and then
the server translate thous requests to tcp and transfer them internally to a py script on the server.
My question is :
My tcp_to_udp script on the server knows that the first request is always the headers and then the data.
How do i make my script know the difference between headers and data ?
I want my script to know what is data and what is headers because now it only
knows that first request is headers but this method is not so good if connection restarts..
Also if its multi connection, to know which headers is connected to which data.
my script now (on the server):
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 32 33 34 35 |
import json import requests import signal import sys import socket from _thread import * UDP_IP = "" UDP_PORT = 5555 s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, 0 ) s.bind((UDP_IP, UDP_PORT)) print ( "Wating for connections" ) def data_iter(): while True : getInfo = data, addr = s.recvfrom( 10000000024 ) print ( "My data:" , data) yield (data) headers = None while headers is None : headers, addr = s.recvfrom( 4024 ) if headers is not None : break headers = headers.decode( "utf-8" ) headers = json.loads(headers) try : except socket.error as error: if error.errno = = errno.EPIPE: print (os.strerror(error.errno)) else : raise |
headers are json type converted to bytes:
1 2 |
headers = b '{"RECORDER_NAME": "USB Audio OnBoard: #1 (hw:0,1)", "LZMA": "1", "RECORDER_RATE": "44100"}' My data: b 'nanannananananna' # because im testing |