Server data transfer problem

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” );
}
//***************************************************************************

Hello,

Please post your output window after running your program and use “code” format on source code. Are you sure the client is connected to your Fastrack? Public IP addresses are not so common on GPRS. Do you see this --> “adl_atSendResponse( ADL_AT_RSP, “\r\n WIP_CEV_OPEN \r\n” )” when connecting with a client?

Hi Tomalex,

i’m facing the same problem with eraydeniz, i have a client ,which when i use to send “this is a test data” to www.yahoo.com , has given me the result :

"inside WIP_CEV_OPEN
Client is COnnected
[WIPEV] WIP_CEV_WRITE @ TCPCLIENT 0x180c6938 (0 bytes)

Inside the TCP Handler

inside the WIP_CEV_WRITE
19"

but for some reason i couldn’t send the data to my other modem which i’m using as a server.
do you have some clue about what problem i might face right now?

this is my source code with a brief explanation.

#include "adl_global.h"
#include "wip.h"
/***************************************************************************/
/*  prototypes                                                             */
/***************************************************************************/
static bool adl_errorHandler( u16 type, ascii * info);

/***************************************************************************/
/*  Mandatory variables                                                    */
/*-------------------------------------------------------------------------*/
/*  wm_apmCustomStackSize                                                  */
/*-------------------------------------------------------------------------*/
/***************************************************************************/
#if __OAT_API_VERSION__ >= 400									//this is where the version of the fastrack memory 
const u16 wm_apmCustomStackSize = 4096;							//is configurated
#else															//the configuration is different between Fastrack and Fastrack supreme
u32 wm_apmCustomStack[1024];
wm_apmCustomStackSize = sizeof(wm_apmCustomStack);
#endif


/***************************************************************************/
/*  Initialization-related event handlers                                  */
/***************************************************************************/
void Timer_Handler (void);
void CekIpHandler (void);
void ClientEventHandler (wip_event_t *Event, void *ctx);
void PingHandler (wip_channel_t Ping,wip_event_t *event, void *ctx);
void ServerEventHandler (wip_event_t *Event, void *ctx);

/***************************************************************************/
ascii GPRS_APN[] = "indosatgprs";									// APN
ascii GPRS_LOGIN[] = "";											// User Name
ascii GPRS_PASSWORD[] = "";											// Password
u16 port = 80;														// port of the server which we trying to connect
ascii IP[]= "12.15.7.214" ;											// the server address which the TCP CLient trying to connect
wip_bearer_t b;														// the bearer profile name
wip_channel_t Channel;												// Variable allocated for the TCP socket server
wip_channel_t Ping;													// channel allocated to make a ping service
wip_channel_t ClientChannel;										// Channel allocated to make a spawned TCP CLient Socket 
/***************************************************************************/
//The Common Handler used for the Custom AT Command

static bool adl_errorHandler( u16 type, ascii * info)				//Handler if there is an error when the error subscribe is failed
{
  return TRUE;
}

void OpenPingHandler (ascii *IP)
{
	Ping = wip_pingCreateOpts (IP, PingHandler, NULL, WIP_COPT_REPEAT, 4, WIP_COPT_END);// Handler to the ping function
}

void CloseBearerHandler (void)										//Handler to the AT+END (to stop the bearer connection)
{
	s8 ret;
	ret = wip_bearerStop (b);
	adl_atSendResponse (ADL_AT_UNS, "inside Close Bearer handler");
}

void OpenBearerHandler (void)										//Handler to AT+OPEN (To start the GPRS bearer connection)
{
	s8 ret;
	ret = wip_bearerStart (b);
	adl_atSendResponse (ADL_AT_UNS, "inside Open Bearer handler");
}

void ReconnectHandler (void)										//Handler to do the auto Reconnect GPRS system
{
	s8 ret;
	ret = wip_bearerStart (b);
	adl_atSendResponse (ADL_AT_UNS, "inside reconnect handler");
	
}

void cobaHandler (adl_atCmdPreParser_t *paras)						//Handler to the AT+PING command. 
{																	//this handler save the number of the destination IP
	switch (paras->Type)											//and opened the Ping Socket to the destination
	{
	case ADL_CMD_TYPE_PARA :
		{
			ascii *alamatIP = ADL_GET_PARAM(paras,0);				//to get the first parameter of AT+PING command
			OpenPingHandler(alamatIP);								//run the ping function
			break;
		}
	}
}

void openClientHandler (void)										//Handler to open the new TCP CLient socket
{
	Channel = wip_TCPClientCreate(IP,port, ClientEventHandler,NULL);
}


/***************************************************************************/
//Handler to managed all the event occured when the bearer is opened, configured, and started
void EventHandler_Bearer(wip_bearer_t b, s8 event, void *ctx)
{
	wip_in_addr_t appIpAddr;
	ascii IpAddr[15];
	s8 sRet;

	int i;

	switch (event)
{
	case WIP_BEV_CONN_FAILED:
{
	wip_bearerStart(b);
	adl_atSendResponse( ADL_AT_RSP, "\r\n WIP_BEV_CONN_FAILED \r\n" );		// send the Event to the Hyper Terminal
	break;
}

case WIP_BEV_IP_CONNECTED:
{
	CekIpHandler ();														// To Check the IP when the first time connected to the internet
	Channel = wip_TCPServerCreate(3000, ServerEventHandler,NULL);		// To Create the Client Socket immediately after the GPRS s connected
	adl_tmrSubscribe (TRUE,300,ADL_TMR_TYPE_100MS, CekIpHandler);			// To periodically (30s) check the modem's IP 


break;
}

case WIP_BEV_IP_DISCONNECTED:
{
ReconnectHandler ();															// calling the Reconnect function when the IP 
adl_atSendResponse( ADL_AT_UNS, "\r\n WIP_BEV_IP_DISCONNECTED \r\n" );			// is disconnected
break;
}

case WIP_BEV_STOPPED:															// triggered when the bearer was stopped on purpose
{
adl_atSendResponse( ADL_AT_RSP, "\r\n WIP_BEV_STOPPED \r\n" );
break;
}

}
}
/****************************************************************************/
//this is the function to managed the AT+CEKIP function

void CekIpHandler (void)
{
	wip_in_addr_t appIpAddr;
	ascii IpAddr[15];
	s8 sRet;
	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);									// Convert the IP Address into ASCII
	wm_sprintf(Buffer, "IP address -> %s\r\n",IpAddr);						// copy the ascii IP address into the buffer 
	adl_atSendResponse (ADL_AT_UNS, Buffer);								// Display your IP address over UART1
}
/************************************************************************/
//This is to capture the call back of SIM initialization  event

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" );		
		adl_atCmdSubscribe("AT+CEKIP", CekIpHandler, ADL_CMD_TYPE_READ);			//make the custom AT+CEKIP command
		adl_atCmdSubscribe("AT+END", CloseBearerHandler, ADL_CMD_TYPE_ACT);			//make the custom AT+END command
		adl_atCmdSubscribe("AT+OPEN", OpenBearerHandler, ADL_CMD_TYPE_ACT);			//make the custom AT+OPEN command
		adl_atCmdSubscribe("AT+PING", cobaHandler, ADL_CMD_TYPE_PARA|0x0011);		//make the custom AT+PING command
		adl_atCmdSubscribe("AT+TCPCLIENT",openClientHandler, ADL_CMD_TYPE_ACT);		//make the custom AT+TCPCLIENT command
	break;
}
}

//***************************************************************************
//This is the function to managed the event related to the CLient Sockets

void ClientEventHandler (wip_event_t *Event, void *ctx)
{
	u32 Read;
	u32 Write;
	ascii *DataBuffer;
	ascii writeBuffer[30];

	adl_atSendResponse (ADL_AT_UNS, "\r\nInside the TCP Handler\r\n");

	switch (Event->kind)
	{
	case WIP_CEV_READ:															//Triggered when the data received by the remote 
		adl_atSendResponse (ADL_AT_UNS, "\r\nInside the WIP_CEV_READ\r\n");		//server is ready to read
		DataBuffer = adl_memGet ((u16) (Event->content.read.readable+1));		//Preparing the memory needed for the incoming data
		wm_memset (DataBuffer,0x00,Event->content.read.readable);				//Set all the memory into 0
		Read = wip_read (Channel, DataBuffer, Event->content.read.readable);	//Read the data send by the remote server
		*(DataBuffer+Read) = '\0';
		if (Read >0)
		{
			adl_atSendResponse (ADL_AT_UNS, DataBuffer);						//send the data read to the external application
			adl_atSendResponse (ADL_AT_UNS,"\r\n");
		}
		else
		{
			adl_atSendResponse (ADL_AT_UNS,"ReadError");						//triggered when the reading process failed
		}

		break;
	
	case WIP_CEV_OPEN:															//triggered when the the Client Socket is connected 
		adl_atSendResponse (ADL_AT_UNS,"\r\ninside WIP_CEV_OPEN\r\n");			//to the remote server
		adl_atSendResponse (ADL_AT_UNS,"\r\nClient is COnnected\r\n");
		break;

	case WIP_CEV_WRITE:															//Triggered when the writing process to the  
		adl_atSendResponse (ADL_AT_UNS,"\r\ninside the WIP_CEV_WRITE\r\n");		//channel is completed
		Write = wip_write(Channel, "this is a test data",19);					//Saving the data into the Write buffer
		wm_itoa (Write,writeBuffer);											//Convert the return value of the writing process into ascii
		adl_atSendResponse (ADL_AT_UNS,writeBuffer);							//Send the return value into Hyper Terminal
		adl_atSendResponse (ADL_AT_UNS,"\r\n");							
		break;
	
	case WIP_CEV_ERROR :														//Triggered when the connecting to remote server
		adl_atSendResponse (ADL_AT_UNS,"\r\ninside the WIP_CEV_ERROR\r\n");		//is failed 
		break;

	case WIP_CEV_PEER_CLOSE :													//Triggered when the CLient Socket is closed
		adl_atSendResponse (ADL_AT_UNS,"\r\ninside the WIP_CEV_PEER_CLOSE\r\n");
		break;

	}
}

/*this is the function to handle the ClientSpawned Socket from the server Socket
/***************************************************************************/


void ServerEventHandler (wip_event_t *Event, void *ctx)
{
	u32 Read;
	u32 Write;
	ascii *DataBuffer;
	ascii writeBuffer[30];

	adl_atSendResponse (ADL_AT_UNS, "\r\nInside the TCP Handler\r\n");

	ClientChannel = Event->channel;

	switch (Event->kind)
	{
	case WIP_CEV_READ:															//Triggered when the data received by the remote 
		adl_atSendResponse (ADL_AT_UNS, "\r\nInside the WIP_CEV_READ\r\n");		//server is ready to read
		DataBuffer = adl_memGet ((u16) (Event->content.read.readable+1));		//Preparing the memory needed for the incoming data
		wm_memset (DataBuffer,0x00,Event->content.read.readable);				//Set all the memory into 0
		Read = wip_read (ClientChannel, DataBuffer, Event->content.read.readable);	//Read the data send by the remote server
		*(DataBuffer+Read) = '\0';
		if (Read >0)
		{
			adl_atSendResponse (ADL_AT_UNS, DataBuffer);						//send the data read to the external application
			adl_atSendResponse (ADL_AT_UNS,"\r\n");
		}
		else
		{
			adl_atSendResponse (ADL_AT_UNS,"ReadError");						//triggered when the reading process failed
		}
		
		adl_memRelease (DataBuffer);
		break;
	
	case WIP_CEV_OPEN:															//triggered when the the Client Socket is connected 
		adl_atSendResponse (ADL_AT_UNS,"\r\ninside WIP_CEV_OPEN\r\n");			//to the remote server
		adl_atSendResponse (ADL_AT_UNS,"\r\nClient is COnnected\r\n");
		Write = wip_write(Channel, "this is a test data",19);					//Saving the data into the Write buffer
		wm_itoa (Write,writeBuffer);											//Convert the return value of the writing process into ascii
		adl_atSendResponse (ADL_AT_UNS,writeBuffer);							//Send the return value into Hyper Terminal
		adl_atSendResponse (ADL_AT_UNS,"\r\n");
		break;

	case WIP_CEV_WRITE:															//Triggered when the writing process to the  
		adl_atSendResponse (ADL_AT_UNS,"\r\ninside the WIP_CEV_WRITE\r\n");		//channel is completed
		break;
	
	case WIP_CEV_ERROR :														//Triggered when the connecting to remote server
		adl_atSendResponse (ADL_AT_UNS,"\r\ninside the WIP_CEV_ERROR\r\n");		//is failed 
		break;

	case WIP_CEV_PEER_CLOSE :													//Triggered when the CLient Socket is closed
		adl_atSendResponse (ADL_AT_UNS,"\r\ninside the WIP_CEV_PEER_CLOSE\r\n");
		break;

	}
}




//This is the function to handle the Ping Command 
/***************************************************************************/

void PingHandler (wip_channel_t Ping, wip_event_t *event, void *ctx)
{
	adl_atSendResponse (ADL_AT_UNS, "\r\nthis is inside the PingHandler\r\n");
	switch (event->kind)
	{
	case WIP_CEV_PING :															//triggered when there is a reply from the 
		adl_atSendResponse(ADL_AT_RSP,"\r\nthis is the ping answered\r\n");		//destination IP Address
		break;
	case WIP_CEV_ERROR :														//Triggered when the sending of ICMP is failed
		adl_atSendResponse (ADL_AT_UNS,"\r\nthe ping is failed\r\n");
		break;
	}
}

//***************************************************************************
void adl_main ( adl_InitType_e InitType )
{
	s8 Retval;
	s32 Result = -1;
	Result = adl_errSubscribe( adl_errorHandler );
if ( OK != Result )
  {
	TRACE (( 1, "adl_errSubscribe failed" ));					//should not happen. Nevermind test it and return here if not available
    return;
  }
	Result = wip_ATCmdSubscribe();
	if ( OK == Result )
  {
/************************this is the main program start*******************************/

	Retval = wip_netInitOpts(WIP_NET_OPT_DEBUG_PORT, WIP_NET_DEBUG_PORT_UART1,WIP_NET_OPT_LOG_EVENTS, TRUE,WIP_NET_OPT_END);
	adl_simSubscribe(EventHandler_Sim, NULL);
	adl_atSendResponse( ADL_AT_RSP, "\r\n Main OK \r\n" );
	adl_atUnSoSubscribe("WIP_BEV_IP_DISCONNECTED",ReconnectHandler);

/*****************************End of the main program*********************************/
	}
else
  {    
    TRACE (( 1, "+WIP AT Commmands subscribtion failed." ));	//error : memory lack within Open AT application
  }
}

Are you sure that your other modem’s IP address is visible :question:

Hi Awneil,

i’m sorry, i don’t really get with what you mean visible? is it that the server’s IP is a public IP? or what? because i’m using the same GPRS set up. and i could retrieve the ip address from my program too. just like below :

at+cekip?
OK
IP address -> 10.33.78.43

and the other problem is my Ping Channel won’t trigger anything neither WIP_CEV_PING (if succeeded) nor WIP_CEV_ERROR (If failed).
could you give a me a hint about this? thank you before.

regards,
edy2

Yes - if it’s not Public, it won’t be visible - or accessible.

I think there’s no guarantee that the IP adress assigned to one unit will be visible to another - even on the same GPRS network.

Even if the IP addresses themselves are visible, the network might not allow (certain types of) messages between them.

General public GPRS networks are designed for mobiles to establish outgoing links to public servers; eg, web browsing - they do not generally allow incoming links to mobiles, nor links between mobiles. If you require these, you will almost certainly require a special subscription - at a special cost!

That will almost certainly just be a local IP address - it will not (necessarily) be accessible to any other unit.

See: viewtopic.php?f=3&t=1699&p=8830&hilit=guarantee#p8830

Also search this forum for “Public IP Address”…

Hi Awneil,

i think my GPRS’s IP is accessible from the outside. because i have turned my wireless CPU to act as a common dial up modem.
i use the gprs feature in my SIM and i use it to connect my computer to the internet. and from another computer i could ping the GPRS IP in my computer.
moreover i could make a web server in my computer using the Fastrack as the modem to connect to the Internet.
does it mean that the IP is accessible from the outside?

regards,
edy2