Kyle Ludwig

InterNiche TCP server: m_listen() and m_recv()

Discussion created by Kyle Ludwig on Dec 22, 2006
Latest reply on Dec 29, 2006 by James Williams
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

Outcomes