AnsweredAssumed Answered

how to continuously try to auto connect?

Question asked by baert jonas on Apr 23, 2009
Latest reply on Jan 21, 2013 by netra

hey I'm using the coldfire-lite tcp client. The board that I'm using is m52233DEMO.I can connect to the server this is working fine. But I wan't to know how to program my board to try continuously make a connection even if the server is not running.  But when I reset or shutdown the server or the board the board has to reconnect but that isn't working.


some information about the server: The server auto drops the connection when there is no reply of board the server knows this because the board is sending a keep_alive to the server. When there is no keep_alive send the server wait's for about 5s and then disconnect the board.


this is a part of code of my tcp_init


int freescale_tcp_init()

    const char* loginname;
    semaphore                         = 0;
    flash_ffs_lockout                 = 0;
    emg_tcp_communication_socket     = INVALID_SOCKET;
    // Init message queue for MINI_TCP socket interface
    msring_init(&emg_tcp_msring, emg_tcp_msring_buf, sizeof(emg_tcp_msring_buf) / sizeof(emg_tcp_msring_buf[0]));

    // Init a socket structure with our Port Number
    emg_tcp_sin.sin_addr.s_addr     = (SERVER_IP);
    emg_tcp_sin.sin_port            = (PORT_NUMBER);

    emg_tcp_communication_socket    = m_socket();

    printf( "\nConnecting to target..." );

    //m_ioctl(emg_tcp_communication_socket, SO_NONBLOCK, NULL);    //make socket non blocking   

    e = m_connect(emg_tcp_communication_socket, &emg_tcp_sin, freescale_tcp_cmdcb );
   if ( e > 0 )
        send_alive = 1;
        if( e == ECONNREFUSED )
            printf( " - Cold Not Find Target, reset" );
                emg_tcp_communication_socket     = INVALID_SOCKET;
                m_close (emg_tcp_communication_socket);
                m_close (emg_tcp_server_socket);
            printf(" - error %d starting listen on emg TCP server\n", e);
                emg_tcp_communication_socket     = INVALID_SOCKET;

          m_ioctl(emg_tcp_communication_socket, SO_NONBLOCK, NULL); //make socket non blocking   

    if (e == 0)
    emg_tcp_server_socket = emg_tcp_communication_socket;