Listening on Multiple Ports

Questions specifically related to the TCP/IP stack that interfaces with the driver.

Listening on Multiple Ports

Postby rwinscot » Sun Mar 28, 2010 8:03 am

From comments in uIP - it's clear that it supports listening on multiple ports at the expense of 2k per each additional port (which is fine). Trouble is, I'm not seeing anything in the documentation or samples on how to accomplish this. Calling uip_listen twice...

uip_listen(HTONS(80));
uip_listen(HTONS(8080));

...doesn't work. Any tips on how to get this working?
rwinscot
 
Posts: 6
Joined: Wed Mar 03, 2010 11:11 pm

Re: Listening on Multiple Ports

Postby GregEigsti » Sun Mar 28, 2010 8:12 am

It seems like you have read the uIP docs? If not you should go grab them as they can probably answer your question.

If you dig through the uIP code you will see that the adding ports to listen on code is not difficult to understand; pretty simple. You will have to differentiate between ports on incoming data in your uip_appcall function.

As close as I have come to this is wedging TCP socket send ability (for SMTP / port 25) into WiServer which listens/connects on port 80.

I also believe that the WiShield/uIP source only allocate one "socket structure" so you will need to modify that code (a #define I believe) to allow more ports to be listened on.

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: 1067
Joined: Sun Aug 02, 2009 5:23 pm
Location: Sammamish WA USA (near Seattle)
  • Website

Re: Listening on Multiple Ports

Postby rwinscot » Sun Mar 28, 2010 2:40 pm

Yes, I've been through the uIP docs... and adding another port should be as I've indicated above - which does not work.

From uIP documentation and code comments, listening on multiple ports is in the design. There are no examples of how to do this... can someone from Asynclabs confirm or deny that this is possible? ...and perhaps a code snippet on how to make it happen?
rwinscot
 
Posts: 6
Joined: Wed Mar 03, 2010 11:11 pm

Re: Listening on Multiple Ports

Postby GregEigsti » Sun Mar 28, 2010 4:15 pm

It works just fine; I have a socketapp sitting here listening to TCP ports 80 and 8080. Its not doing anything anything other than accepting/printing/closing the connection but I can clearly connect to either port on the WiShield via telnet - and the Serial.print()s reflect that this does indeed work. Of course the WiShield and uIP stack are only single tasking so you are only going to be able to service incoming connections one at a time - but there may be a way to work around that with uIP pthreads.

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: 1067
Joined: Sun Aug 02, 2009 5:23 pm
Location: Sammamish WA USA (near Seattle)
  • Website

Re: Listening on Multiple Ports

Postby rwinscot » Sun Mar 28, 2010 6:56 pm

Interesting... I must be doing something wrong then. Would you post the code? It would help put me on solid ground.
rwinscot
 
Posts: 6
Joined: Wed Mar 03, 2010 11:11 pm

Re: Listening on Multiple Ports

Postby GregEigsti » Sun Mar 28, 2010 9:25 pm

Here you go, its the socketapp example all moved into the sketch/pde with unnecessary stuff stripped out. It was tested with WEP 128.

My apps-conf.h has the following standard change
Code: Select all
//Here we include the header file for the application(s) we use in our project.
//#define APP_WEBSERVER
//#define APP_WEBCLIENT
#define APP_SOCKAPP
//#define APP_UDPAPP
//#define APP_WISERVER


And my uip-conf.h has been changed as follows; UIP_CONF_MAX_CONNECTIONS probably did not need to be changed and I think its probably critical to change UIP_CONF_MAX_LISTENPORTS.
Code: Select all
/**
* Maximum number of TCP connections.
*
* \hideinitializer
*/
#define UIP_CONF_MAX_CONNECTIONS 2

/**
* Maximum number of listening TCP ports.
*
* \hideinitializer
*/
#define UIP_CONF_MAX_LISTENPORTS 2


And the sketch
Code: Select all
/*
* Socket App
*
* A simple socket application example using the WiShield 1.0
*/

#include <WiShield.h>
extern "C" {
#include "uip.h"
}

// Wireless configuration parameters ----------------------------------------
#define WIRELESS_MODE_INFRA      1
#define WIRELESS_MODE_ADHOC      2
unsigned char local_ip[]       = {192,168,1,10};  // IP address of WiShield
unsigned char gateway_ip[]     = {192,168,1,1};   // router or gateway IP address
unsigned char subnet_mask[]    = {255,255,255,0}; // subnet mask for the local network
const prog_char ssid[] PROGMEM = {"SSID"};        // max 32 bytes
unsigned char security_type    = 0;               // 0 - open; 1 - WEP; 2 - WPA; 3 - WPA2
// WPA/WPA2 passphrase
const prog_char security_passphrase[] PROGMEM = {"12345678"};   // max 64 characters
// WEP 128-bit keys
prog_uchar wep_keys[] PROGMEM = {
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  // Key 0
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  // Key 1
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,  // Key 2
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; // Key 3
// setup the wireless mode
unsigned char wireless_mode = WIRELESS_MODE_INFRA;
unsigned char ssid_len;
unsigned char security_passphrase_len;
//---------------------------------------------------------------------------

void setup()
{
   //set up serial communications
   Serial.begin(57600);
   WiFi.init();
}

void loop()
{
   WiFi.run();
}

extern "C" {
/*---------------------------------------------------------------------------*/
/*
* The initialization function. We must explicitly call this function
* from the system initialization code, some time after uip_init() is
* called.
*/
void socket_app_init(void)
{
   /* We start to listen for connections on TCP ports 80 and 8080. */
   uip_listen(HTONS(80));
   uip_listen(HTONS(8080));
}
/*---------------------------------------------------------------------------*/
/*
* In socketapp.h we have defined the UIP_APPCALL macro to
* socket_app_appcall so that this function is uIP's application
* function. This function is called whenever an uIP event occurs
* (e.g. when a new connection is established, new data arrives, sent
* data is acknowledged, data needs to be retransmitted, etc.).
*/
void socket_app_appcall(void)
{
   if(uip_connected()) {
      Serial.print("Accepted connection on port: ");
      Serial.println(ntohs(uip_conn->lport));
      uip_close();
   }
}
/*---------------------------------------------------------------------------*/
}

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: 1067
Joined: Sun Aug 02, 2009 5:23 pm
Location: Sammamish WA USA (near Seattle)
  • Website

Re: Listening on Multiple Ports

Postby rwinscot » Sun Mar 28, 2010 11:53 pm

Awesomeness. This works perfectly... thanks!
rwinscot
 
Posts: 6
Joined: Wed Mar 03, 2010 11:11 pm

Re: Listening on Multiple Ports

Postby GregEigsti » Mon Mar 29, 2010 12:23 am

Good to hear! I was a little worried that the "pre-post" cleanup tweaked things :D
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: 1067
Joined: Sun Aug 02, 2009 5:23 pm
Location: Sammamish WA USA (near Seattle)
  • Website


Return to TCP/IP Stack

Who is online

Users browsing this forum: No registered users and 1 guest