AnsweredAssumed Answered

Can´t maintain two sockets connected at time

Question asked by edgarsevilla on Sep 12, 2012
Latest reply on Apr 23, 2015 by Garabo

I have implemented a server that handles two sockets

 

A client can connect to any of these sockets (X or Y) and start sharing information in appropriately way.

 

But when a client attempts to connect to both sockets of the server, the server fails. No matter the order of the connection request to the sockets, the first connection request always works and the second fails (accept function). Now when I get the error, it is 0 (zero).

 

I have noticed that if the client connects to a socket, then sends the necessary data and then closes the socket before starting a new connection, then there are no faults. But obviously I do not want to be opening and closing connections to the server.

 

Anyone know how to solve this problem?

 

Server:

    Kinetis k60 (Tower Kit):

    MQX 3.7

    Codewarrior 10.1

 

Client:

    PC (Linux)


 

Socket_Y = socket(...);
...
stServerAddr.sin_port = Port_X;
...
bind(Socket_X, ...);
listen(Socket_X, ...);
...
stServerAddr.sin_port = Port_Y;
...
bind(Socket_Y, ...);
listen(Socket_Y, ...);

....

while(1)
{
    SocketTemp = RTCS_selectall(10);
    if(SocketTemp )
    {
        if(SocketTemp == Socket_X)
        {
            ClientSocket1 = accept(Socket_X,...)
            if(ClientSocket1 = -1)
            {
                RTCS_geterror(Socket_X)
            }
        }
        else if(SocketTemp == Socket_Y)
        {
            ClientSocket2 = accept(Socket_Y,...)
            if(ClientSocket2 = -1)
            {
                RTCS_geterror(Socket_Y)
            }
        }
        else if(SocketTemp == ClientSocket1)
        {
            error = recv(...)
            if(error = -1)
            {
                shutdown(ClientSocket1,...)
            }
            else
            {
                send(...)
            }
        }
        else if(u32SocketTemp == ClientSocket2)
        {
            error = recv(...)
            if(error = -1)
            {
                shutdown(ClientSocket2,...)
            }
            else
            {
                send(...)
            }
        }
        else
        {
            /* Not recognized */
        }
    }
    else
    {
        /* TimeOut -- Nothing to do */
    }
}

 

Regards,

Edgar Sevilla


Outcomes