InterNiche TCP server: m_listen() and m_recv()

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

InterNiche TCP server: m_listen() and m_recv()

1,274 Views
wyliek
Contributor I
hi there

I'm trying to implement a TCP server on the M52233DEMO with interniche's TCP/IP stack. However, cant seem to get m_recv() to work.

I set up a socket called tcp_socket using m_listen() as follows:


int e;

tcp_sin.sin_addr.s_addr = (0);
tcp_sin.sin_port = (5005);
tcp_socket = m_listen(&tcp_sin, tcp_cmdcb, &e);
m_ioctl(tcp_socket, SO_NONBLOCK, 0);


and it works just fine. However, I dont know when to use m_recv():


int err;
char tcp_data[10];

err =m_recv( tcp_socket, &tcp_data[0] , 9 );
printf("%i", err);


I have a task running that executes the above code. err always returns -1 which indicated that m_recv() failed. When I look at tcp_socket.error i see it equals to 6. This tells me that there is no tcp data available for the non-blocking socket. I have used ethereal to check and the board is receiving tcp data packets. Am I not using m_recv() properly?

Here is my callback function tcp_cmdcb()

int tcp_cmdcb(int code, M_SOCK so, void * data)
{
int e = 0;
char tcp_data[10];
//LED3_TOGGLE;
switch(code)
{
case M_OPENOK:
socket_ready=1;
break;

case M_CLOSED:
m_close( so );
socket_ready=0;
break;

case M_RXDATA:
if (socket_ready==1)
{
err =m_recv( tcp_socket, &tcp_data[0] , 9 );
printf("%i", err);
}
break;

case M_TXDATA:
e = -1;
break;

default:
dtrap();
return 0;
}

USE_VOID(data);
return e;
}

Does anyone have any simple code to receive data form a single tcp socket using m_listen and m_recv()?

Thanks
Kyle
Labels (1)
0 Kudos
1 Reply

277 Views
DrSeuss
Contributor I

You cannot call m-recv from within the callback.

Use the web server as a example of how to use the queue with callback functions.

0 Kudos