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 5 of 5

Thread: multiple tcp connection?

  1. #1
    Junior Member
    Join Date
    Jul 2010
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default multiple tcp connection?

    Hi,

    i am doing a network program that requires multiple TCP/IP connection at the same time
    the problem is i need the multiple connection on the client side so it's not possible to do the
    accept() method with threading.

    what i need is that the client can send multiple requests to different nodes while he listen to them all on the same port after sending the request.
    the reason behind this is,I have to mange 100s or 1000s of connections and it would be wasteful to create a new connection with a new port for each node. even if i can mange with lots of ports, I just want to know if there is a way around this.

    I've heard that java doesn't support the select() method which i was informed that it's used in multiplexing.

    any thoughts?

    Nasser


  2. #2
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: multiple tcp connection?

    listen to them all on the same port after sending the request.
    I'm not sure what you are asking. The Socket constructor uses an IP address and port for the remote, server host.

    How do you specify what port the client is to use?
    You need to open a Socket for each remote host you want to connect to.

    Are you suggesting that after the client sents a request, that the client would become a server and then listen on one port for future communications from the sites that it initially connected to as a client.

  3. #3
    Junior Member
    Join Date
    Jul 2010
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: multiple tcp connection?

    There is a constructor for the socket that you can specify the
    destination IP/ destination port /local IP /local port

    Socket(InetAddress address, int port, InetAddress localAddr, int localPort)

    when i send the requests i call this constructor for each connection with different socket objects with the same local port but I'd change the destination IP, so it should be fine as long as the IP is different.
    but it gives an error that the address is already in use for some reason when i try to open the 2nd socket.

    Are you suggesting that after the client sents a request, that the client would become a server and then listen on one port for future communications from the sites that it initially connected to as a client.
    That's exactly what i mean!
    but in addition not just listening it also can send.

  4. #4
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: multiple tcp connection?

    That's exactly what i mean!
    Use a ServerSocket to listen on at a port for future communications.

    Use threads to allow sending on one socket while listening at another port.

  5. #5
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: multiple tcp connection?

    it gives an error that the address is already in use
    Can you write a small program that shows the error, execute the program and copy and paste the program and the full text of the error message here?

Similar Threads

  1. Autocomplete over telnet connection
    By April in forum Java Networking
    Replies: 6
    Last Post: June 17th, 2010, 08:58 AM
  2. Thread and connection
    By Param in forum Threads
    Replies: 0
    Last Post: April 26th, 2010, 03:43 AM
  3. how can i connect with a dial up connection
    By reguapo in forum Java Networking
    Replies: 1
    Last Post: February 2nd, 2010, 06:21 AM
  4. Unable to create a new connection!
    By fh84 in forum JDBC & Databases
    Replies: 1
    Last Post: November 20th, 2009, 05:58 PM
  5. cant get rid of http connection
    By kartik in forum Java Networking
    Replies: 1
    Last Post: July 21st, 2009, 03:09 AM