TCP/IP server data transfer problem


#1

Hi,

I am working on TCP/IP data transfer by using fastrack supreme 20 modem.
I can create TCP/IP connection with client and server mode. There is no problem with client mode.
But I have a problem with server mode. I can create TCP/IP server connection.
But I can only send just one data package and I can not see sending data on hyper terminal,

How I can solve this problem and if possible please send a code sample which uses the server data transfer.

Thanks,

Following my source code for server data transfer :
/***************************************************************************/
#include “adl_global.h”
#include “wip.h”
/***************************************************************************/
const u16 wm_apmCustomStackSize = 1024;
/***************************************************************************/
ascii GPRS_APN[] = “internet”; //APN
ascii GPRS_LOGIN[] = “”; // User Name
ascii GPRS_PASSWORD[] = “”; // Password

wip_in_addr_t my_address = 0;
ascii MyIPAddress[15];
wip_bearer_t b;
wip_channel_t Handle_Channel;
ascii buffer[1000];
/***************************************************************************/
void EventHandler_Channel(wip_event_t *ev, void *ctx)
{
switch (ev->kind)
{
case WIP_CEV_DONE:
{
adl_atSendResponse( ADL_AT_RSP, “\r\n WIP_CEV_DONE \r\n” );
break;
}

case WIP_CEV_ERROR:
{
    adl_atSendResponse( ADL_AT_RSP, "\r\n WIP_CEV_ERROR \r\n" );
	break;
}

case WIP_CEV_OPEN:
{      
    adl_atSendResponse( ADL_AT_RSP, "\r\n WIP_CEV_OPEN \r\n" );
	break;
}

case WIP_CEV_PEER_CLOSE:
{
    adl_atSendResponse( ADL_AT_RSP, "\r\n WIP_CEV_PEER_CLOSE \r\n" );
	break;
}

case WIP_CEV_PING:
{
    adl_atSendResponse( ADL_AT_RSP, "\r\n WIP_CEV_PING \r\n" );
	break;
}

case WIP_CEV_READ:
{
adl_atSendResponse(ADL_AT_RSP", "\r\n WIP_CEV_READ \r\n");

While ( wip_read(Handle_Channel, buffer, 1000) > 0)
    {
	adl_atSendResponse(ADL_AT_RSP", "\r\n While loop \r\n");
	adl_atSendResponse(ADL_AT_RSP", buffer);
}

	break;
}

case WIP_CEV_WRITE:
{
    adl_atSendResponse( ADL_AT_RSP, "\r\n WIP_CEV_WRITE \r\n" );
	break;
}

}
}
/***************************************************************************/
void OpenTCPServerPort(void)
{
Handle_Channel = wip_TCPServerCreate(3000, EventHandler_Channel, NULL);

if (Handle_Channel == NULL)
{
    adl_atSendResponse( ADL_AT_RSP, "\r\n OpenTCPServerPort NULL \r\n" );     
}
else
{
    adl_atSendResponse( ADL_AT_RSP, "\r\n OpenTCPServerPort \r\n" );
} 

}
/***************************************************************************/
void EventHandler_Bearer(wip_bearer_t b, s8 event, void *ctx)
{
wip_in_addr_t appIpAddr;
ascii IpAddr[15];
s8 sRet;
ascii TempString[100];

switch (event)
{
case WIP_BEV_CONN_FAILED:
{
wip_bearerStart(b);
adl_atSendResponse( ADL_AT_RSP, “\r\n WIP_BEV_CONN_FAILED \r\n” );
break;
}

case WIP_BEV_IP_CONNECTED:
{
    ascii Buffer[50];
    sRet = wip_bearerGetOpts(b,WIP_BOPT_IP_ADDR,&appIpAddr,WIP_BOPT_END); // Get your IP address
    wip_inet_ntoa(appIpAddr, IpAddr,15);
    wm_sprintf(Buffer, "IP address -> %s\r\n",IpAddr);
    adl_atSendResponsePort (ADL_AT_RSP, ADL_PORT_UART1, Buffer); // Display your IP address over UART1

    OpenTCPServerPort();
	break;
}
  
case WIP_BEV_IP_DISCONNECTED:
{
    adl_atSendResponse( ADL_AT_RSP, "\r\n WIP_BEV_IP_DISCONNECTED \r\n" );
	break;
}
  
case WIP_BEV_STOPPED:
{
	adl_atSendResponse( ADL_AT_RSP, "\r\n WIP_BEV_STOPPED \r\n" );
	break;
}

}
}
//***************************************************************************
void EventHandler_Sim(u8 event)
{
int r;

switch (event)
{
	case ADL_SIM_EVENT_FULL_INIT:
	  r = wip_bearerOpen(&b, "GPRS", EventHandler_Bearer, NULL);
	  r = wip_bearerSetOpts(b, WIP_BOPT_GPRS_APN, GPRS_APN, WIP_BOPT_LOGIN,GPRS_LOGIN, WIP_BOPT_PASSWORD, GPRS_PASSWORD, WIP_BOPT_END);
	  r = wip_bearerStart(b);

	  adl_atSendResponse( ADL_AT_RSP, "\r\n ADL_SIM_EVENT_FULL_INIT \r\n" );   

	  break;
}

}
//***************************************************************************
void adl_main ( adl_InitType_e InitType )
{
s8 Retval;
Retval = wip_netInit();
adl_simSubscribe(EventHandler_Sim, NULL);
adl_atSendResponse( ADL_AT_RSP, “\r\n Main OK \r\n” );
}
//***************************************************************************


#2

crosspost:
viewtopic.php?f=16&t=2263


#3

First, server sockets don’t support read/write: they spawn new communication channels for each connection request (that’s necessary to handle several clients simultaneously). So, the event handler doesn’t describe events on the server channel, but on a newly created communication channel, which is stored in field ev->channel, but is not Handle_channel.

Moreover, beware that buffers returned by wip_read() aren’t zero-terminated strings. Unless you’re lucky, when printing that buffer without appending a ‘\0’ at the right place, you’ll send random non-ASCII garbage to the hyper terminal, which isn’t exactly a robust application…

Finally, if you add <<WIP_NET_OPT_DEBUG_PORT, WIP_NET_DEBUG_PORT_UART1>> to the options passed to wip_netInitOpts(), you’ll be able to use <<wip_debug( const char *fmt, …)>>, which acts just as a printf(), and can be easily redirected to TMT traces, other UARTs, or NULL.


#4

thanks your advice,

I use firmware version 663c and I use wiplib3.0
I have got a " Wavecom Open AT IP Connectivity Development Guide (wiplib 3.0) pdf " and I write a sample code tcp/ip server data transfer in development guide by te Wavecom. But I can not execute wavecom sample server data transfer with my fatsrac supreme 20 modem.

wavecom sample server data transfer:

/***************************************************************************/
#include “adl_global.h”
#include “wip.h”
/***************************************************************************/
const u16 wm_apmCustomStackSize = 1024;
/***************************************************************************/
ascii GPRS_APN[] = “internet”; //APN
ascii GPRS_LOGIN[] = “”; // User Name
ascii GPRS_PASSWORD[] = “”; // Password

wip_in_addr_t my_address = 0;
ascii MyIPAddress[15];
wip_bearer_t b;
/***************************************************************************/
void commHandler(wip_event_t *ev, void *ctx)
{
u8 *buffer[16];
s32 nread;

wip_channel_t c = ev->channel;	

switch (ev->kind)
{

case WIP_CEV_OPEN:
{      
    wip_write(c, MSG_WELCOME, strlen(MSG_WELCOME);
	break;
}

case WIP_CEV_PEER_CLOSE:
{
    adl_atSendResponse( ADL_AT_RSP, "\r\n WIP_CEV_PEER_CLOSE \r\n" );
	break;
}

case WIP_CEV_PING:
{
    adl_atSendResponse( ADL_AT_RSP, "\r\n WIP_CEV_PING \r\n" );
	break;
}

case WIP_CEV_READ:
{
nread = wip_read(c, buffer, sizeof(buffer));

if(!strncasecmp(buffer, "name", nread))
wip_write(c, "Name", strlen("Name"));

else if(!strncasecmp(buffer, "forename", nread)
wip_write(c, "FoName", strlen("ForName"));

else if(!strncasecmp(buffer, "phone", nread)
wip_write(c, "FoName", strlen("ForName"));

else if(!strncasecmp(buffer, "phone", nread)
wip_close(c);

else 

wip_write(c, MSG_SYNTAX_ERROR, strlen(MSG_SYNTAX_ERROR));
return;
}

case WIP_CEV_WRITE:
case WIP_CEV_ERROR:
case WIP_CEV_PEER_CLOSE:
return;

}
}
/***************************************************************************/
void OpenTCPServerPort(void)
{

wip_channel_t server = wip_TCPServerCreate(3000, &commHandler, NULL);	

}
/***************************************************************************/
void EventHandler_Bearer(wip_bearer_t b, s8 event, void *ctx)
{
wip_in_addr_t appIpAddr;
ascii IpAddr[15];
s8 sRet;
ascii TempString[100];

switch (event)
{
case WIP_BEV_CONN_FAILED:
{
wip_bearerStart(b);
adl_atSendResponse( ADL_AT_RSP, “\r\n WIP_BEV_CONN_FAILED \r\n” );
break;
}

case WIP_BEV_IP_CONNECTED:
{
    ascii Buffer[50];
    sRet = wip_bearerGetOpts(b,WIP_BOPT_IP_ADDR,&appIpAddr,WIP_BOPT_END); // Get your IP address
    wip_inet_ntoa(appIpAddr, IpAddr,15);
    wm_sprintf(Buffer, "IP address -> %s\r\n",IpAddr);
    adl_atSendResponsePort (ADL_AT_RSP, ADL_PORT_UART1, Buffer); // Display your IP address over UART1

    OpenTCPServerPort();
	break;
}
  
case WIP_BEV_IP_DISCONNECTED:
{
    adl_atSendResponse( ADL_AT_RSP, "\r\n WIP_BEV_IP_DISCONNECTED \r\n" );
	break;
}
  
case WIP_BEV_STOPPED:
{
	adl_atSendResponse( ADL_AT_RSP, "\r\n WIP_BEV_STOPPED \r\n" );
	break;
}

}
}
//***************************************************************************
void EventHandler_Sim(u8 event)
{
int r;

switch (event)
{
	case ADL_SIM_EVENT_FULL_INIT:
	  r = wip_bearerOpen(&b, "GPRS", EventHandler_Bearer, NULL);
	  r = wip_bearerSetOpts(b, WIP_BOPT_GPRS_APN, GPRS_APN, WIP_BOPT_LOGIN,GPRS_LOGIN, WIP_BOPT_PASSWORD, GPRS_PASSWORD, WIP_BOPT_END);
	  r = wip_bearerStart(b);

	  adl_atSendResponse( ADL_AT_RSP, "\r\n ADL_SIM_EVENT_FULL_INIT \r\n" );   

	  break;
}

}
//***************************************************************************
void adl_main ( adl_InitType_e InitType )
{
s8 Retval;
Retval = wip_netInit();
adl_simSubscribe(EventHandler_Sim, NULL);
adl_atSendResponse( ADL_AT_RSP, “\r\n Main OK \r\n” );
}
//***************************************************************************