UPD receieved data mixed-up

UPD receieved data mixed-up

Postby nl2ttl » Tue Jul 30, 2013 7:20 am

I have a simple hardware project that sends the following data over the netwerk by using UDP protocol.

UDP Port 8234

Datatstring: unique_number and reader number

When I have only on sender ther is no problem, only when I jabe multiple senders like 8 PCB's that sending data, the received data get broken. When they send like:

12377678-A01
16645678-A02
15545678-A03
14445678-A04

The data string becomes like: 123-A0277678-A0112377678 or something like that.

So I think i have to send a STX and ETX only how can I check for STX and ETX when data strings get mixed-up
nl2ttl
 
Posts: 10
Joined: Fri May 17, 2013 1:44 pm

Re: UPD receieved data mixed-up

Postby stranac » Tue Jul 30, 2013 7:25 am

You should post some code.
Make sure you use code tags.
Friendship is magic!

R.I.P. Tracy M. You will be missed.
User avatar
stranac
 
Posts: 1097
Joined: Thu Feb 07, 2013 3:42 pm

Re: UPD receieved data mixed-up

Postby nl2ttl » Tue Jul 30, 2013 9:31 am

Code: Select all

import datetime
import socket
import sys

UDP_IP = "192.168.100.75"                                         # Local host IP voor UDP receiver
UDP_PORT = 8234                                 # UDP Poort RS232 -> UDP module

def proces_UDP_data():
   now = datetime.datetime.now()
   print "IP Adress van de zender:   ", Source_IP
   print "Ontvangen data:         ", data
   print "ReaderNr:                      ", Reader_Nr
   print "TAG Serial:                    ", Tag_Serial   
   print "Data ontvangen om:      ", now.strftime("%Y-%m-%d %H:%M:%S")
   print " "

# Start een UDP socket
sock = socket.socket(socket.AF_INET,       
                     socket.SOCK_DGRAM)
sock.bind((UDP_IP, UDP_PORT))

# Ontvangst loop
while True:
   data, addr = sock.recvfrom(1024)        # buffer size is 1024 bytes
   Source_IP = (str(addr)[2:16])          # wanneer het een string geworden is kan ik een deel van de string gebruiken
   Reader_Nr = data[0:3]
   Tag_Serial = data[3:13]                   # haal het Serienummer uit de TAG
   proces_UDP_data();

nl2ttl
 
Posts: 10
Joined: Fri May 17, 2013 1:44 pm

Re: UPD receieved data mixed-up

Postby codyf86 » Tue Jul 30, 2013 6:46 pm

Hi,

UDP packets aren't guaranteed to be received in the same order that they're sent. I have a lot of experience with TCP/stream sockets but not a lot with UDP, but can you add a header to each packet that tells it's sorted number. Then read the header information and use a sorting call to sort them in to order first.
codyf86
 
Posts: 3
Joined: Mon Jul 08, 2013 7:25 pm

Re: UPD receieved data mixed-up

Postby nl2ttl » Tue Jul 30, 2013 10:22 pm

I tried the TCPIP socket send function. But the same thing happend.
8 PCB's sending data over socket 8234.

Script only say IP connected from first PCB that sends data.
After that it received al data from al other PCB with different IP. But still mixed it up

Code: Select all
#!/usr/bin/env python

import socket

TCP_IP = '192.168.100.75'
TCP_PORT = 8234
BUFFER_SIZE = 20  # Normally 1024, but we want fast response

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind((TCP_IP, TCP_PORT))
s.listen(1)

conn, addr = s.accept()
print 'Connection address:', addr
while 1:
    data = conn.recv(BUFFER_SIZE)
    if not data: break
    print "received data:", data
    conn.send(data)  # echo
conn.close()
nl2ttl
 
Posts: 10
Joined: Fri May 17, 2013 1:44 pm

Re: UPD receieved data mixed-up

Postby ochichinyezaboombwa » Wed Jul 31, 2013 4:30 am

Your TCP code is an exact copy from http://docs.python.org/2/library/socket.html -- except for
Code: Select all
BUFFER_SIZE = 20  # Normally 1024, but we want fast response
which is totally ridiculous.

However you didn't post your client code and didn't show what exactly is "the same thing happend".

There is no magic.
ochichinyezaboombwa
 
Posts: 200
Joined: Tue Jun 04, 2013 7:53 pm

Re: UPD receieved data mixed-up

Postby nl2ttl » Wed Jul 31, 2013 7:28 am

Yes it is a exact copy, because I am totaly lost at this point.

I Tried the BUFFER_SIZE = 20 because the total size of the package is 20 bytes.
The client side is a MicroController with a serial to TCP/IP module from:

http://www.alibaba.com/product-gs/516864688/RS232_Serial_to_Ethernet_TCP_IP.html

What I tried is the following:

Create a small loop script (python) that sends 1000 times in 2 seconds the string I send from the MicroController.
Run this on 3 different PC's and take a look at the server side. At that point there is no Mixed up data on the server side.
nl2ttl
 
Posts: 10
Joined: Fri May 17, 2013 1:44 pm


Return to Networking

Who is online

Users browsing this forum: No registered users and 1 guest