Oh!, sorry about that. I’m using WIP 3.00.07, OpenAT OS 3.13.02 and Firmware 657c. I’m pasting my socket, hope that might help…
void Hdlr_TCPSocket ( wip_event_t *Event, t2r_cx_state *ctx ) {
u32 read;
u32 write;
u8 *DataBuffer;
wip_channel_t wct_Channel;
TRACE ( ( 1, "Hdlr_TCPSocket: Entering" ) );
wct_Channel = Event->channel;
TRACE ( ( 1, "Hdlr_TCPSocket: Channel: %d", Event->channel ) );
//TRACE (( 1, "SpawnCanalServer en TCP_Handler: %d", SpawnCanalServer ));
switch ( Event->kind ) {
case WIP_CEV_READ:
TRACE ( ( 1, "Hdlr_TCPSocket: WIP_CEV_READ" ) );
if(ctx == (t2r_cx_state *) NULL) {
u8 cadena[255];
TRACE ( ( 1, "Hdlr_TCPSocket: ctx NULL" ) );
sprintf ( cadena, "Socket Error. CTX NULL" );
wip_write ( wct_Channel, cadena, (u32) strlen(cadena) );
wip_close ( wct_Channel );
}
else {
DataBuffer = adl_memGet ( ( Event->content.read.readable + 1 ) + 100 );
wm_memset ( DataBuffer, 0x00, Event->content.read.readable );
//(DataBuffer+read)='\0';
// ctx->cx0
while ( ( read = wip_read ( ctx->cx0, DataBuffer, Event->content.read.readable ) ) > 0 ) {
DataBuffer[Event->content.read.readable] = '\0';
TRACE ( ( 1, "Hdlr_TCPSocket: Read: %s", DataBuffer ) );
// If RS232 port is open, data is sent
if ( t2r_RS232_Open )
adl_fcmSendData ( V24M_Handle, DataBuffer, Event->content.read.readable );
//adl_atSendResponsePort(ADL_AT_UNS, ADL_PORT_UART1, DataBuffer);
//adl_atSendResponsePort(ADL_AT_UNS, ADL_PORT_UART1, "\r\n");
}
adl_memRelease ( DataBuffer );
}
break;
case WIP_CEV_WRITE:
TRACE ( ( 1, "Hdlr_TCPSocket: WIP_CEV_WRITE" ) );
break;
case WIP_CEV_OPEN:
TRACE ( ( 1, "Hdlr_TCPSocket:WIP_CEV_OPEN" ) );
if( ctx == (t2r_cx_state *) NULL ) { // First conn
// Looking for a free conn context
u16 i;
for ( i = 0; i < T2R_TCPMAXCLIENTE; i++ ) {
if ( t2r_cx_table[i].state == T2R_FREE ) {
ctx = (t2r_cx_state*) &t2r_cx_table[i];
ctx->state = T2R_CONNECTED;
ctx->cx0 = wct_Channel;
wip_setCtx ( wct_Channel, ctx );
TRACE ( ( 1, "Hdlr_TCPSocket: ctx NULL Opening RS232" ) );
// As a channel has been opened, serial port data mode activates
T2R_Start_RS232Comm ( );
}
}
if ( i <= T2R_TCPMAXCLIENTE && ctx != (t2r_cx_state*) NULL ) {
TRACE ( ( 1, "Hdlr_TCPSocket: Conn number %d", i - 1 ) );
write = wip_write ( ctx->cx0, "Conected\n\r", 10 );
}
else {
u8 cad[255];
TRACE ( ( 1, "Hdlr_TCPSocket: Max number of connection reached" ) );
sprintf ( cad, "Max number of connections reached\n\r" );
write = wip_write ( ctx->cx0, cad, (u32) strlen ( cad ) );
wip_close ( wct_Channel );
}
}
else {
// Context should be empty
TRACE ( ( 1, "Hdlr_TCPSocket: Context is not null when openning connection" ) );
wip_close ( wct_Channel );
}
break;
case WIP_CEV_ERROR:
case WIP_CEV_PEER_CLOSE:
TRACE ( ( 1, "Hdlr_TCPSocket:WIP_CEV_PEER_CLOSE" ) );
if ( ctx != (t2r_cx_state*) NULL && ctx->state == T2R_CONNECTED ) {
wip_close ( ctx->cx0 );
ctx->state = T2R_FREE;
}
else if ( ctx != (t2r_cx_state*) NULL ) {
wip_close ( wct_Channel );
ctx->state = T2R_FREE;
}
else {
wip_close ( wct_Channel );
}
T2R_CloseRS232 ( );
break;
default:
TRACE ( ( 1, "Hdlr_TCPSocket:Not Controlled error: %d", Event->kind ) );
break;
}
}