Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
16 years ago

Multiple socket server

Hi everyone!

I a Nios newbie, so I'm sorry if I'm asking any FAQ, but I can't find any information on the subject.

I want to build a multiport socket server

For example, imagine server which allows 3 connections:

- port 23 which is a simple telnet terminal

- port 6 which echoes back everything

- port 1024 which bridges data to and from a serial port

I started with the simple_server_socket template.

Everything works fine as long as I listen only one of the above ports. If more than a port is listening, only the one whose task has higher priority will work; the others seems to connect but no data is transferred; then after a while a get a stream of "No free buffers for rx " error messages from the jtag debug port.

Another issue I have is on connection closing.

If the server closes it, there no problem and my client can reconnect.

If the client closes the connection, the server doesn't recognize it and remain in a connected state. If I try to reconnect I get the same behaviour and errors as described above with a multiple connection.

Thank you for any help

Regards

3 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Further information:

    The problems arises when I call select() for both sockets, waiting for a connection.

    The higher priority one works

    The lower priority one connects (the client is connected) but select() doesn't return and the data actually is not accepted.

    I tried to set the select() call non blocking (zero timeout) and inserting a TK_SLEEP() after it, as suggested in a previous post, but select() still blocks.

    Any ideas?

    On the other hand I solved the problem with connection closing: recv() was not tested for zero return values, indicating that the client closed the connection.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Actually I had understood there was some sort of problem with the select() function, so I solved the problem with a non-blocking call and forcing a sleep if there's no data available from the socket.

    i.e. :

    if (select(max_socket, &readfds, NULL, NULL, &tout) <= 0) {

    TK_SLEEP(5);

    continue;

    }

    with a zero tout.

    Now I will look at the patch you suggested which is probably better.

    Thank you for your help Slacker.