Multi-Threaded server which can handle UDP, TCP clients

Discussion in 'Linux Networking' started by Ravindra.B, Jan 7, 2009.

  1. Ravindra.B

    Ravindra.B Guest

    Hello there,

    I would like to implement a multi-threaded server which can accept
    requests from both TCP as well as UDP clients. Can anyone suggest how
    to proceed for this?

    After contemplating it, following are my doubts regarding the
    1) Is there any way by which we can decipher in the server program
    weather it is TCP/UDP request so that it can be handled accordingly.
    2) Since the server should handle both TCP, UDP requests, I think I
    need to create two sockets for both TCP and UDP in the server program?
    If yes, is it possible to reuse same port and IP address for two
    different sockets??

    Please suggest me the best way to implement it.

    Thanks in advance
    Ravindra. B
    Ravindra.B, Jan 7, 2009
    1. Advertisements

  2. Ravindra.B

    Ravindra.B Guest

    Hi Max,

    Thanks for the replay. Please find my queries in line.
    Ravindra.B, Jan 7, 2009
    1. Advertisements

  3. Ravindra.B

    Ravindra.B Guest

    Ravindra.B, Jan 8, 2009
  4. Each TCP connection that you are handling will be its own socket. You
    will also have one socket for accepting new TCP connections. You would
    also have a single UDP socket.
    A TCP port and a UDP port are two completely different things. Using
    TCP port 3012 has no effect on UDP port 3012. They are like 112 Main
    Street and 112 Jackson Avenue.
    Or by using a pool of threads, which usually provides the highest
    It may or may not be required, depending on the protocol you are
    implementing on top of UDP. Many UDP protocols support the client
    changing its IP address, and so they don't use the source IP of the
    UDP datagram to find the state. But you can do it that way if you want

    David Schwartz, Jan 8, 2009
  5. As long as the work doesn't involve disk I/O. You can't stop doing any
    work on every connection while you wait for data to be read from disk.

    David Schwartz, Jan 11, 2009
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.