Page 1 of 1

wifi plus UDP server Net_Wireless_MCW1001_TCP_Accept probem

Posted: 04 Nov 2012 16:40
by pichon
Hello ,

The demo HTTP_Demo (Net_Wireless_MCW1001 demo for MCW1001 module) is running correctly on my site after a http://wifi_ip_adresse in a browser .

I modified the HTTP_Demo (Net_Wireless_MCW1001 demo for MCW1001 module) to manage only Request UDP server


3 change in RunHttpServer to move "TCP port 80" to "UDP port 10001"

Code: Select all

void RunHttpServer() {

  Lcd_Cmd(_LCD_CLEAR);
  Lcd_Out(1,1,txt8);
  Lcd_Out(2,1,txt9);
  
  rfIconMark = 3;
  DrawRfIcon();
  
  while(1) {
    socketHandle = 0;
    backLog = 1;
    
    //localPort = 80;   [color=#BF0000]modif  1[/color] 
   localPort = 10001;
    ////////////////////////////////
    
    
    //Net_Wireless_MCW1001_SocketCreate(&socketHandle, _NET_WIRELESS_MCW1001_SOCKET_TYPE_TCP);   // Create TCP socket  [color=#BF0000]Modif 2[/color]
    Net_Wireless_MCW1001_SocketCreate(&socketHandle, _NET_WIRELESS_MCW1001_SOCKET_TYPE_UDP);   // become  UDP socket 
    ///////////////////////////////////////////////////////////////////////////
    
    
    Net_Wireless_MCW1001_SocketBind(socketHandle, &localPort, &bindResponse);                  // Bind socket to the listen port
    Net_Wireless_MCW1001_TCP_Listen(socketHandle, &backLog, &listenResponse);                  // Prepare the socket to listen for connection
                                                                                               // with one children socket.
    while(1) {
      socketChild = socketHandle;
      

      Net_Wireless_MCW1001_TCP_Accept(&socketChild, &remotePort, remoteIpAdd);                 // Accept incoming conncetion
      if (socketChild != 254) {                                                                // Accept function set socketChild.
        break;                         


      }
    }
   //[color=#BF0000]Modif 3[/color]
    Lcd_Out(2,1,"should Detect UDP_HERE socketChild !=254  but nothing  ?  ");
    Delay_ms(2000);
    ////////////////////////////////////////////////////
    
    //SendHttpResponse();
    Net_Wireless_MCW1001_SocketClose(socketChild);                                             // Close sockets
    Net_Wireless_MCW1001_SocketClose(socketHandle);
  }
}
when i use the tool UDP Terminal to send a request UDP on port 10001 nothing with Net_Wireless_MCW1001_TCP_Accept socketChild stay all time at the value 254

Have you any Idea ..... OK with TCP port 80 but not with UDP port 10001

I used mikroc Pro for Pic 5.61 with PIC18F45K22 + WiFi PLUS Click Board


best regards
Herve

Re: wifi plus UDP server Net_Wireless_MCW1001_TCP_Accept pro

Posted: 05 Nov 2012 15:42
by dejan.odabasic
Hello,

This line could be the cause of your issue:

Code: Select all

Net_Wireless_MCW1001_TCP_Listen(socketHandle, &backLog, &listenResponse);                  // Prepare the socket to listen for connection
Best regards.

Re: wifi plus UDP server Net_Wireless_MCW1001_TCP_Accept pro

Posted: 05 Nov 2012 22:09
by pichon
Thank for your idea move Net_Wireless_MCW1001_TCP_Listen to Net_Wireless_MCW1001_UDP_Listen

I tested directly Net_Wireless_MCW1001_UDP_ReadBytes without Net_Wireless_MCW1001_TCP_Listen and without Net_Wireless_MCW1001_TCP_Accept , in a loop the function UDP_Readbytes have alway error timeout(100).

how to be listen on port server UDP

Perhat theses functions server to manage UDP request are missing !
Net_Wireless_MCW1001_UDP_Listen not in the library
Net_Wireless_MCW1001_UDP_Accept not in the library


I try to migrate a programm with SPI Ethernet ENC24J600 or SPI Ethernet ENC28J60 to net_wirless_mcw1001_18
client UDP OK
server HTTP tcp port 80 OK
but server UDP missing something but what ....

thank for your help
best regards
Herve

Re: wifi plus UDP server Net_Wireless_MCW1001_TCP_Accept pro

Posted: 08 Nov 2012 14:40
by dejan.odabasic
Hello,

There are no missing functions, as you mentioned you only need to execute Net_Wireless_MCW1001_UDP_ReadBytes function in while loop.
Try to set:

Code: Select all

Net_Wireless_MCW1001_TimeToWait = 1;
before executing for example

Code: Select all

response = Net_Wireless_MCW1001_UDP_ReadBytes(&socketHandle, amount, &remotePort, remoteIPAdd, udpBuffer, &numOfReceiveBytes);
Are you incrementing Net_Wireless_MCW1001_Time variable in timer interrupt service routine?

Best regards.

Re: wifi plus UDP server Net_Wireless_MCW1001_TCP_Accept pro

Posted: 08 Nov 2012 23:23
by pichon
Hello ,

Thanks for your help , now it's working with UDP server and HTTP in same time

i attached the file to share this code WiFi_HTTP_Demo.c

Code: Select all

void RunHttpServer() {

//UDP   modifié Herve
  unsigned int numOfReceiveBytes_udp = 0;
  unsigned int amountOfDataToBeRead_udp=0;
  unsigned char remoteIP_udp[4];
  unsigned int remotePort_udp=0;
  ////////////////////////////////////////

  Lcd_Cmd(_LCD_CLEAR);
  Lcd_Out(1,1,txt8);
  Lcd_Out(2,1,txt9);
  
  rfIconMark = 3;
  DrawRfIcon();
  
  while(1) {
    socketHandle = 0;
    backLog = 1;
    localPort = 80;
    Net_Wireless_MCW1001_SocketCreate(&socketHandle, _NET_WIRELESS_MCW1001_SOCKET_TYPE_TCP);   // Create TCP socket
    Net_Wireless_MCW1001_SocketBind(socketHandle, &localPort, &bindResponse);                  // Bind socket to the listen port
    Net_Wireless_MCW1001_TCP_Listen(socketHandle, &backLog, &listenResponse);                  // Prepare the socket to listen for connection
                                                                                               // with one children socket.

//UDP modifié herve
   localPort_udp =10001 ;   //  listen   port 10001
   Net_Wireless_MCW1001_SocketCreate(&socketHandle_udp, _NET_WIRELESS_MCW1001_SOCKET_TYPE_UDP);    //Create UDP socket
   Net_Wireless_MCW1001_SocketBind(socketHandle_udp, &localPort_udp , &bindResponse_udp);                  // Bind socket to the listen port UDP

    while(1) {
    
    // UDP   modifié Herve  only a sample to work  not finish
        Net_Wireless_MCW1001_TimeToWait = 1;    // Important:  it's the minimun , lost or consume here 1 seconde 
                                                // improve :  Net_Wireless_MCW1001_TimeToWait secondes each loop Net_Wireless_MCW1001_UDP_ReadBytes
                                                // Net_Wireless_MCW1001_TCP_Accept  don't need timeout to detect  TCP request
        numOfReceiveBytes_udp=0;
        Net_Wireless_MCW1001_UDP_ReadBytes(&socketHandle_udp, amountOfDataToBeRead_udp, &remotePort_udp, remoteIP_udp, getRequest_udp, &numOfReceiveBytes_udp);
        if ( numOfReceiveBytes_udp != 0 )  //receive numOfReceiveBytes_udp  of  char in dat
           {
            getRequest_udp[numOfReceiveBytes_udp]=(char ) 0 ;
           
            Lcd_Cmd(_LCD_CLEAR);
            Lcd_Out(1,1,"UDP Receive");
            Lcd_Out(2,1,getRequest_udp);
            
            Net_Wireless_MCW1001_SocketClose(socketHandle_udp);
            Net_Wireless_MCW1001_SocketCreate(&socketHandle_udp, _NET_WIRELESS_MCW1001_SOCKET_TYPE_UDP);
            Net_Wireless_MCW1001_SocketBind(socketHandle_udp, &localPort_udp , &bindResponse_udp);
           }
   
    //UDP FIN //////////////////////
 
 
      socketChild = socketHandle;
      Net_Wireless_MCW1001_TCP_Accept(&socketChild, &remotePort, remoteIpAdd);                 // Accept incoming conncetion
      if (socketChild != 254) {
            Lcd_Cmd(_LCD_CLEAR);
            Lcd_Out(1,1,"TCP  Receive ");                                                                // Accept function set socketChild.
             break;                                                                                 // If socketChild == 254 there is no incoming connection
                              }


             }

    SendHttpResponse();
    Net_Wireless_MCW1001_SocketClose(socketChild);                                             // Close sockets
    Net_Wireless_MCW1001_SocketClose(socketHandle);
           }
}

remark : The loop on function Net_Wireless_MCW1001_UDP_ReadBytes is perfect but if you have no request UDP you wait the value of Net_Wireless_MCW1001_TimeToWait here 1 seconde.
ehancement will be to have same function without timeout as Net_Wireless_MCW1001_TCP_Accept.

Wifi plus is a very nice product , i will work on client http not use a this time in my project .


Best Regards
Herve