Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Handling TCP and UDP in same server

  1. #1
    Junior Member
    Join Date
    Nov 2011
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Handling TCP and UDP in same server

    Hi, i need to create a server that handles both tcp and upd

    so i have like:

    ServerSocket tcpServer = new ServerSocket(port) // for tcp connection
    ....
    DatagramSocket udpServer = new DatagramSocket(port) // for udp connections

    What I want to know is how can I check if im receiving a TCP connection or a UDP connection ?

    ex:
    if(tcpConnection){ //do things}
    ...
    if(udpConnection){ //do other things }


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,140
    Thanks
    65
    Thanked 2,720 Times in 2,670 Posts

    Default Re: Handling TCP and UDP in same server

    The ServerSocket blocks until it receives a connection.
    I don't know what the DatagramSocket does.

    Do you have a small simple client/server program that would demonstrate this problem?

  3. #3
    Junior Member
    Join Date
    Jan 2011
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Handling TCP and UDP in same server

    Well you certainly can't use the same port.... so you are going to have to use one for the UDP server and the another one for the TCP one!

Similar Threads

  1. Event Handling
    By maress in forum What's Wrong With My Code?
    Replies: 0
    Last Post: January 24th, 2011, 03:29 AM
  2. Thread handling
    By _lithium_ in forum What's Wrong With My Code?
    Replies: 8
    Last Post: January 12th, 2011, 12:14 AM
  3. Regarding File Handling
    By ravjot28 in forum File I/O & Other I/O Streams
    Replies: 1
    Last Post: March 1st, 2010, 07:45 PM
  4. Event handling
    By subhvi in forum AWT / Java Swing
    Replies: 3
    Last Post: August 26th, 2009, 11:20 AM
  5. Exception handling
    By AnithaBabu1 in forum Exceptions
    Replies: 6
    Last Post: August 27th, 2008, 09:37 AM