satinder singh

New to TCP\IP need help....

Discussion created by satinder singh on Apr 23, 2010
Latest reply on Apr 27, 2010 by satinder singh

Hi All,

 

I am new to TCP\IP and want to develop a server application with MCF52259 i.e my board will be in listening mode and the communication will be initiated by a remote client. For developing this application I am using FNET stack for freescale. To develop my confidence I am trying to recieve a byte from remote client and send the same back to the client but I am unable to do it. I am pasting my test code, can someone help me and suggest if I am doing something wrong.

 

/*******************************/

int main(void)
{

int   server_socket,client_socket;
unsigned int   data_length = 1;
int   data_length1 = 1;
unsigned int   RecvMsgSize=0;
char   TCPIPRxBuffer[256];
 struct sockaddr_in    server_address,client_address;

 

 /*creating a listening socket*/
 server_socket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);

 

 /*filling the relevant data */
fnet_memset(&server_address, 0, sizeof(server_address));  
server_address.sin_family = AF_INET;
server_address.sin_addr.s_addr = INADDR_ANY;
server_address.sin_port = 1234;

 /*binding the socket address to the listening socket*/
 if((FNET_OK == bind(server_socket, (struct sockaddr *) &server_address,sizeof(server_address))))
 {
 /*binding successful*/
 }
 else
 {
 fnet_printf("\nbinding error\n");            
 }

 if((FNET_OK == listen(server_socket, 10)))
 {
            /*listening on socket*/
}
else
{
fnet_printf("\nlistening error\n");            
}

 

    while (TRUE)
    {
        /*waiting for a connection and accepting it*/
        data_length1 = sizeof(client_address);
        client_socket = accept(server_socket,(struct sockaddr *) &client_address,
        &data_length1);
    
        /*recieving from accepted connection*/    
        if(FNET_OK == recv(client_socket,(char*)TCPIPRxBuffer,data_length1,0))
        {

       }
        
        send(client_socket, (char*)TCPIPRxBuffer, 256, 0);


        /*closing the socket*/
        if(FNET_OK == closesocket(client_socket))
        {
            
        }
        else
        {
              fnet_printf("\nsocket closing error\n");            
        }
    }

}

 

 

Please suggest whether I am missing something or doing something wrong.

 

Regards,

 

Satinder Singh

Outcomes