Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 UDP to TCP requests script

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):

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)

headers = None
while headers is None:
    headers, addr = s.recvfrom(4024)
    if headers is not None:
headers = headers.decode("utf-8")
headers = json.loads(headers)

    r ='', headers=headers, data=data_iter())
except socket.error as error:
    if error.errno == errno.EPIPE:
data type :
headers are json type converted to bytes:
headers  = b'{"RECORDER_NAME": "USB Audio OnBoard: #1 (hw:0,1)", "LZMA": "1", "RECORDER_RATE": "44100"}'
My data: b'nanannananananna' # because im testing

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Configuring requests module to use secondary IP on server for outbound requests mohit 1 2,581 Oct-24-2016, 05:21 PM
Last Post: nilamo

Forum Jump:

Users browsing this thread: 1 Guest(s)