F5F Stay Refreshed Power Users Networks Data exchange via UDP on identical ports between two network segments

Data exchange via UDP on identical ports between two network segments

Data exchange via UDP on identical ports between two network segments

A
aguzz123123
Senior Member
599
08-03-2023, 07:17 PM
#1
Hello. I aim to transmit a 1.5 MB file via UDP between two network interfaces. Communication must occur exclusively on port 3007 for both source and destination ports. In typical operating systems, the IP stack chooses which port to use next, which we cannot control here. Using the same source_port for every data packet risks buffer overflow. You mentioned testing in Python with sockets—do you have any suggestions for Ruby, Python, or Java that could help enforce fixed source and destination ports?
A
aguzz123123
08-03-2023, 07:17 PM #1

Hello. I aim to transmit a 1.5 MB file via UDP between two network interfaces. Communication must occur exclusively on port 3007 for both source and destination ports. In typical operating systems, the IP stack chooses which port to use next, which we cannot control here. Using the same source_port for every data packet risks buffer overflow. You mentioned testing in Python with sockets—do you have any suggestions for Ruby, Python, or Java that could help enforce fixed source and destination ports?

N
Nejc007
Senior Member
707
08-03-2023, 08:34 PM
#2
No, I did not define MTU in the software.
N
Nejc007
08-03-2023, 08:34 PM #2

No, I did not define MTU in the software.

I
Ice3Boy
Member
230
08-04-2023, 11:13 AM
#3
Do you manage the software fully on both sides? If yes, create a pseudo-TCP program that transmits parts of a file in small chunks along with their positions. The receiver should verify receipt and confirm completeness. This could be a playful challenge: send 1.5MB in 1500 pieces, each with an index. As you envision it, SND would start, sending data while the receiver checks and asks if it’s missing. After all parts arrive, RCV confirms everything is there. Then SND signals completion and ends.
I
Ice3Boy
08-04-2023, 11:13 AM #3

Do you manage the software fully on both sides? If yes, create a pseudo-TCP program that transmits parts of a file in small chunks along with their positions. The receiver should verify receipt and confirm completeness. This could be a playful challenge: send 1.5MB in 1500 pieces, each with an index. As you envision it, SND would start, sending data while the receiver checks and asks if it’s missing. After all parts arrive, RCV confirms everything is there. Then SND signals completion and ends.

M
Michele02
Junior Member
16
08-06-2023, 08:02 AM
#4
I work to set buffer_size and handle UDP fragmentation. It’s crucial that every packet sent to the device includes both source and destination ports, otherwise delivery fails. I use a similar approach in Python by dividing the file into segments and transmitting them, but I’m encountering issues where the receiving end doesn’t recognize IPv4 fragmented IP packets (not visible in Wireshark). On the sending side, I’m experiencing buffer overflow errors.
M
Michele02
08-06-2023, 08:02 AM #4

I work to set buffer_size and handle UDP fragmentation. It’s crucial that every packet sent to the device includes both source and destination ports, otherwise delivery fails. I use a similar approach in Python by dividing the file into segments and transmitting them, but I’m encountering issues where the receiving end doesn’t recognize IPv4 fragmented IP packets (not visible in Wireshark). On the sending side, I’m experiencing buffer overflow errors.

R
RainbowCrazy
Member
229
08-07-2023, 09:48 AM
#5
This appears to be a software issue rather than a networking concern. Please share your code for examination.
R
RainbowCrazy
08-07-2023, 09:48 AM #5

This appears to be a software issue rather than a networking concern. Please share your code for examination.

A
amandabuddy
Member
56
08-07-2023, 03:11 PM
#6
PYTHON Client - script try to send 1.5MB test.png file import socket import os import time def get_file_packet_count(filename, buffer_size): byte_size = os.stat(filename).st_size packet_count = byte_size//buffer_size if byte_size%buffer_size: packet_count += 1 return packet_count def send_packet(data): sock.sendto(data, target) while True: try: data, messenger = sock.recvfrom(buff_size) data = data.decode() if data == "CONFRIMED": break except: continue time.sleep(0.00001) def send_file(filename): data = None while not data == "READY": print("Waiting for READY state from server side") ready_message = message % ("IS_READY", "_", 0) sock.sendto(ready_message.encode(), target) time.sleep(0.001) try: data, messenger = sock.recvfrom(buff_size) data = data.decode() except: pass time.sleep(0.01) packet_count = get_file_packet_count(filename, buff_size) init_message = message % ("INITIATE", "Duplicate_" + filename, packet_count) sock.sendto(init_message.encode(), target) f = open(filename, "rb") if sock is not None: print("Sending %s with %d packets" % (filename, packet_count)) for i in range(0, packet_count): send_packet(f.read(buff_size)) print("Sent all %d packets\n" % (packet_count)) f.close() message = "%s***%s***%d" PORT = 3007 MY_ADDR = "29.0.0.210" buff_size = 1024 * 5 target = (MY_ADDR, 3007) sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) sock.bind(('', PORT)) sock.settimeout(.02) send_file("test.png") Server - waiting for connection import socket from time import time PORT = 3007 MY_ADDR = "0.0.0.0" buff_size = 1024 * 5 sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) sock.bind((MY_ADDR, PORT)) sock.settimeout(.02) INIT_MODE = True packets = [] f_write_stream = None packet_count = 0 print("Waiting for traffic") if sock is not None: while True: try: data, messenger = sock.recvfrom(buff_size) except: continue if INIT_MODE: data = data.decode() # Intent***filename***packet_count message, filename, packet_count = data.split("***") packet_count = int(packet_count) if message == "INITIATE": print("Receiving %s with %d packets" % (filename, packet_count)) f_write_stream = open(filename, "wb") INIT_MODE = False packets = [] elif message == "IS_READY": sock.sendto("READY".encode(), messenger) else: packets.append(data) sock.sendto("CONFRIMED".encode(), messenger) if len(packets) == packet_count: print("Writing %s with %d packets\n" % (filename, packet_count)) for packet in packets: f_write_stream.write(packet) f_write_stream.close() INIT_MODE = True f_write_stream = None packet_count = 0 written_packets_count = 0
A
amandabuddy
08-07-2023, 03:11 PM #6

PYTHON Client - script try to send 1.5MB test.png file import socket import os import time def get_file_packet_count(filename, buffer_size): byte_size = os.stat(filename).st_size packet_count = byte_size//buffer_size if byte_size%buffer_size: packet_count += 1 return packet_count def send_packet(data): sock.sendto(data, target) while True: try: data, messenger = sock.recvfrom(buff_size) data = data.decode() if data == "CONFRIMED": break except: continue time.sleep(0.00001) def send_file(filename): data = None while not data == "READY": print("Waiting for READY state from server side") ready_message = message % ("IS_READY", "_", 0) sock.sendto(ready_message.encode(), target) time.sleep(0.001) try: data, messenger = sock.recvfrom(buff_size) data = data.decode() except: pass time.sleep(0.01) packet_count = get_file_packet_count(filename, buff_size) init_message = message % ("INITIATE", "Duplicate_" + filename, packet_count) sock.sendto(init_message.encode(), target) f = open(filename, "rb") if sock is not None: print("Sending %s with %d packets" % (filename, packet_count)) for i in range(0, packet_count): send_packet(f.read(buff_size)) print("Sent all %d packets\n" % (packet_count)) f.close() message = "%s***%s***%d" PORT = 3007 MY_ADDR = "29.0.0.210" buff_size = 1024 * 5 target = (MY_ADDR, 3007) sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) sock.bind(('', PORT)) sock.settimeout(.02) send_file("test.png") Server - waiting for connection import socket from time import time PORT = 3007 MY_ADDR = "0.0.0.0" buff_size = 1024 * 5 sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) sock.bind((MY_ADDR, PORT)) sock.settimeout(.02) INIT_MODE = True packets = [] f_write_stream = None packet_count = 0 print("Waiting for traffic") if sock is not None: while True: try: data, messenger = sock.recvfrom(buff_size) except: continue if INIT_MODE: data = data.decode() # Intent***filename***packet_count message, filename, packet_count = data.split("***") packet_count = int(packet_count) if message == "INITIATE": print("Receiving %s with %d packets" % (filename, packet_count)) f_write_stream = open(filename, "wb") INIT_MODE = False packets = [] elif message == "IS_READY": sock.sendto("READY".encode(), messenger) else: packets.append(data) sock.sendto("CONFRIMED".encode(), messenger) if len(packets) == packet_count: print("Writing %s with %d packets\n" % (filename, packet_count)) for packet in packets: f_write_stream.write(packet) f_write_stream.close() INIT_MODE = True f_write_stream = None packet_count = 0 written_packets_count = 0