Help with ideas on keeping 2 udp connections

Questions specifically regarding the WiShield 1.0 family driver.

Help with ideas on keeping 2 udp connections

Postby zack » Tue Jul 20, 2010 3:25 pm

Here's what I need to accomplish:
I have a linux pc and an BlackWidow (with a LCD display and a few buttons) on the same subnet. I have it set up such that I can send some periodic messages to the BW to be displayed on the LCD, I'm doing this with udp packets sent from the linux pc using netcat. This works fine, however I also need to be able to send udp packet to the linux machine when buttons are pressed on the BW to make the linux pc do some things. This is where I've run into a problem. Basically, I need to have a listener on port X on the linux pc waiting for button press commands from the BW, while I'm doing that I'm not able to send the periodic messages from Linux->BW since I will have to send the packet from source port X as well and I get a port-in-use error on the linux pc.
One way to solve the problem is for me to listen on port X on the linux machine while I use port Y for sending the periodic packets to the BW. This does not appear to be possible on the BW, since the rport gets fixed to a single value (either by explicitly setting it when I do uip_udp_new() or implicitly based on the src port value of the first incoming packet).
First question is: is there a way to deal with 2 udp connections at the same time on the BW (both unidirectional).
2nd question: If this is not possible, can you think of any other way to accomplish what I need.

Thanks
zack
 
Posts: 6
Joined: Tue Jul 20, 2010 3:09 pm

Re: Help with ideas on keeping 2 udp connections

Postby zack » Tue Jul 20, 2010 7:08 pm

Ok, so I started browsing through the uip code and it appears that there is support for multiple udp connections except that there is no way to pass in a "connection handle" along with the send function. I'm guessing that I have to:
1. Create the second connection and save the returned handle
2. When I get the upcall, I have to watch for the poll event and try to match the connection handle and when this happens call send() to send the packet.
zack
 
Posts: 6
Joined: Tue Jul 20, 2010 3:09 pm

Re: Help with ideas on keeping 2 udp connections

Postby GregEigsti » Wed Jul 21, 2010 10:25 am

You don't need to save and restore connection handles; when your UIP_APPCALL function is called state will be set correctly for the particular socket that caused the call to happen. Sounds like what you want to do would work much better as a connection based TCP socket.
Check out the wiki!
uIP Stack Docs
Compatible Access Point List
WiShield user contrib branch - DNS, DHCP, AP Scanning, bug fixes, etc.
SlackLab.org - My geek projects blog.
User avatar
GregEigsti
 
Posts: 955
Joined: Sun Aug 02, 2009 5:23 pm
Location: Sammamish WA USA (near Seattle)

Re: Help with ideas on keeping 2 udp connections

Postby zack » Wed Jul 21, 2010 1:58 pm

Well, I need to store the connection handle so I can compare the callback connection context with what I have stored to do the right thing. For example if I have 2 connections to the remote host and I want to send Message A to connection 1, when I get the callback I need to know if I'm in the context of connection 1 or 2. This I can do by comparing the global uip_udp_conn with my stored connection handle.
Also. for anyone trying to do multiple UDP connections: remember to change the "#define UIP_CONF_UDP_CONNS" in uip-conf.h from the default "1" to the number of connections you want.
zack
 
Posts: 6
Joined: Tue Jul 20, 2010 3:09 pm

Re: Help with ideas on keeping 2 udp connections

Postby GregEigsti » Thu Jul 22, 2010 10:16 am

so I can compare the callback connection context with what I have stored to do the right thing.

This makes sense - what I was trying to say was that when your UIP_APPCALL is called it is done on behalf the socket for which there was activity so you don't need to explicitly track your socket "handles" in order to correctly work with uIP. How many other devices is your BW communicating with? Just the PC or other devices as well (how many socket pairs are you using)?

Why not a TCP socket? I have had trouble with UDP socket apps remaining alive for periods longer than 12-24 hours; this can be "worked around" but I have not had the same problem with TCP sockets. And if I am understanding correctly TCP sockets will remove the need to track your sockets for context.

change the "#define UIP_CONF_UDP_CONNS" in uip-conf.h

Lately I have making this (or same for TCP) NEEDED + 1 just in case ;) This setting is set in apps-conf.h (for one stop shopping) in the user contrib branch - makes it a bit easier to change the common stack/app settings in one place.

Greg
Check out the wiki!
uIP Stack Docs
Compatible Access Point List
WiShield user contrib branch - DNS, DHCP, AP Scanning, bug fixes, etc.
SlackLab.org - My geek projects blog.
User avatar
GregEigsti
 
Posts: 955
Joined: Sun Aug 02, 2009 5:23 pm
Location: Sammamish WA USA (near Seattle)

Re: Help with ideas on keeping 2 udp connections

Postby zack » Fri Jul 23, 2010 1:29 pm

Greg, thanks for the tips. The UDP solution has been working Ok for the last 3 days without problems (so far). I chose UDP because I did not need any reliability (the backend S/W periodically pushes data to the BW) and also because it is light weight (although for my application it probably does not make a difference). To answer your question, yes the BW talks to a single linux pc (same IP address).
Another interesting thing I noticed was that when sending out packets from BW to PC the first packet is always dropped, I'm guessing the first packet initiates an ARP and gets dropped by the stack (well, it is UDP so that is probably to be expected).
zack
 
Posts: 6
Joined: Tue Jul 20, 2010 3:09 pm

Re: Help with ideas on keeping 2 udp connections

Postby Kj1 » Wed Sep 01, 2010 7:12 am

Hi Zack,

I'm facing a similar problem. Could you post your code used for assigning both udp connections and the appcode to differentiate between the two connections?

Thanks!
Kj1
 
Posts: 2
Joined: Tue Aug 31, 2010 7:42 am

Re: Help with ideas on keeping 2 udp connections

Postby zack » Wed Sep 01, 2010 9:30 am

I don't have the code handy, I'll post it soon.
zack
 
Posts: 6
Joined: Tue Jul 20, 2010 3:09 pm

Re: Help with ideas on keeping 2 udp connections

Postby zack » Thu Sep 02, 2010 3:20 pm

Here you go (keep in mind this code is not very robust)
Code: Select all
#include "uip.h"
#include "udpapp.h"
#include "config.h"

struct uip_udp_conn *udp_conn2;
extern struct uip_udp_conn *uip_udp_conn;

void udpapp_init(void)
{
    uip_ipaddr_t addr;
    struct uip_udp_conn *c;

    uip_ipaddr(&addr, 192,168,20,10);
    c = uip_udp_new(&addr, HTONS(0));
    if(c != NULL) {
        uip_udp_bind(c, HTONS(41345));
    }
   
    uip_ipaddr(&addr, 192,168,20,10);
    udp_conn2 = uip_udp_new(&addr, HTONS(41344));
    if(udp_conn2 != NULL) {
        uip_udp_bind(udp_conn2, HTONS(41344));
    }
}


void udpapp_appcall(void)
{
    if(uip_poll() && (uip_udp_conn == udp_conn2) && (send_cmd[0] != 0)) {
    //This is the 2nd connection, here I'm just sending out a packet
    //In my example I only use the 2nd connection to send data out
    //there is nothing coming in
      send_cmd_request(send_cmd);
      send_cmd[0] = 0;
    }
    else {
    //else this has to be the first connection
      if(uip_newdata() && !newMsg && parse_msg()) {
          uip_flags &= (~UIP_NEWDATA);
      }
    }
}
zack
 
Posts: 6
Joined: Tue Jul 20, 2010 3:09 pm

Re: Help with ideas on keeping 2 udp connections

Postby spidermonkey04 » Sun Sep 05, 2010 11:57 pm

Zack, did you ever find anything out about the retransmit? I think I'm having the same problem...

---Jared
spidermonkey04
 
Posts: 55
Joined: Thu Oct 29, 2009 6:45 pm

Next

Return to WiShield 1.0 Driver

Who is online

Users browsing this forum: No registered users and 2 guests