2 JVMs Each want same port

I am working on a new approach to where I need to have a class instantiated which will make use of a port. This class will appear in multiple JVMs. I want to start with port 8100 and add one if the previous is busy.
The function to find a vacant port:
public static String getPort( int seed ) {
     while( true )
          try {
               System.out.println("");
               System.out.println(instanceID + " Checking port " + Integer.toString(seed));
               System.out.println("");
               ServerSocket srv= new ServerSocket(seed);
               srv.close();
               srv=null;
               return seed;
          catch( IOException e ) {     
               seed++;
JVM 1 (each have the getPort() function)
Something mything = new Something(getPort(8100));
This gets 8100 as it should.
JVM 2
Something mything = new Something(getPort(8100));
This gets 8100 and it should NOT. It should get 8101. Is there a better way of getting a port like this?
Thanks,
Steffan

Quite easily done: launch this program repeatedly and see what happens:
import java.io.*;
import java.net.*;
public class SSTest {
    public static void main(String[] args) throws Exception {
        ServerSocket ss = createServerSocket(8100, 8121);
        int port = ss.getLocalPort();
        System.out.println("acquired port " + port);
        Thread.sleep(10 * 1000);
        ss.close();
        System.out.println("closed port " + port);
    static ServerSocket createServerSocket(int initialPort, int ubPort) {
        for(int i = initialPort; i < ubPort; ++i) {
            try {
                return new ServerSocket(i);
            } catch (IOException e) {
                System.out.format(
                    "new ServerSocket(%d) fails: %s%n", i, e.getMessage());
        return null;
}

Similar Messages

  • Two applications wants to read on the same port using Socket

    I have an application running on one machine using TCP/IP socket. The data transfer with the other application on other machine is in ASCII.
    Now I want a new application that can have a copy of data received and sent on the given port, where the previous application is running.
    Is it possible in Java using socket and TCP/IP to have two application reading data from the same port and both can read all the data.

    Even when you don't state the type of app which need to read the data stream (is it a server or a client app???), it's impossible to share a single TCP/IP socket among multiple apps.
    Perhaps the best thing to do is to develop something like a proxy server who listens on the nominated port and provides to contact (if your apps are server ones) or to be contacted (if your apps are client ones) by the desired apps.
    This way, the only job for the proxy is to duplicate the contents of the data stream and make them available to all the apps engaged.
    Hope this helps.

  • How do I open the same ports on an Airport Extreme Base Station for multiple computers at the same time?

    As the title suggests...
    I have a mix of five Mac and PC's at home using an Airport Extreme Base Station as the router.   I need many ports opened on the AEBS for all of the computers- not just one computer.  (for example: three people want to play TF2 on Steam at the same time; each machine needs the correct ports open on the router).   Port forwarding  only allows me to forward a given port to a single IP, yet I need that port open for five differnt IP's, all at the same time. 
    How do I do that on an AEBS?
    In the same way, I have a small office of four iMacs using an old airport with the same exact issue.   I would like to be able to connect to all of them remotely with Apple Remote Desktop, but the port forwarding on the airport only allows a port to forward to a single IP.   I want to be able to tunnel into the office network and log onto any machine behind the Airport extreme... not just a single IP.    I currently have it set up where I can tunnel into the office from my house, I can find the one machine that the port forwarding has been assigned to, I can log on and everything is just fine... with one machine.    How do I open the firewall for the other machines? 
    TL,DR version:  How do you open ports on an Airport Extreme Base Station instead of forwarding ports?   Forwarding ports doesn't work for multiple IP's.  

    You can open a single or multiple ports to a single device or different ports to different devices, but you cannot open the same port to multiple devices via the AirPort Utility for the Apple routers.

  • Creating a serverSocket while sonnecting to a socket on the same port

    I want to make a file transfer application for multiple clients, there will not be a server that users will connect to, the application serves as client AND server, every client will have a serversocket object listen for new connections (it will recieve a connection when someone wants to send a file to them) and I will also have a socket object that will connect to a client when I want to send a file to them.
    Is it possible to run all these connections on a single port? Or will there be a conflict?

    836981 wrote:
    I want to make a file transfer application for multiple clients, there will not be a server that users will connect to, the application serves as client AND server, every client will have a serversocket object listen for new connections (it will receive a connection when someone wants to send a file to them)Read up on peer-to-peer.
    and I will also have a socket object that will connect to a client when I want to send a file to them.A new socket for each outbound connection.
    Is it possible to run all these connections on a single port?Yes. A serversocket listens for connections to a specific port number, it can accept many connections.
    Or will there be a conflict?No. Your outbound connections will not use the same port number locally.
    You are more likely to encounter problems with clients (peers) behind NAT routers.

  • HELP!!: Two server application instances could work in the same port?

    Hi everybody!!!
    i have two server application instances over the same JVM and both of them need to get requests from the same port, how can i get this??
    I`m not interested on using RMI, and i wouldn`t like to use sockets, because i have already using XML-RPC, so if you can tell me how can i get this without using sockets nor RMI, please help me...
    I don�t if there any way using threads??
    thanks a lot,
    JCPARRAM

    Two sockets can't be bound to the same port on the same machine at the same time. This means that one application can't have two sockets listening on the same port and that two applications can't each have a socket listening on the same port (no matter what language they are written in, and, if they are in Java, no matter whether they are on the same JVM or not).
    Your only solution is to make one of the server applications listen on a different port.

  • Can you have multiple RMI Servers listen at the same port?

    Hi,
    I am wondering if is possible to assign many RMI servers to the same port. I have a working RMI system that is assigning a single server to a specified port when the server is created. I need to scale my project to incorporate Activation and the ability to go through a firewall. I have the power to punch holes in the firewall, so I am thinking that I would like to set up a port for all my activated servers to listen on. Is this possible to put them all on one port?

    Yes you are correct. However, I am wanting the actual servers listening on the same port. I have noticed that when I do not assign a port number when binding my RMI servers to the registry, then the rmi system sets them all up listening on the same port. This port is random and changes each time I restart my server system, which rebinds all the servers to the rmiregistry again. I am look for a way to use custom socket factories and then tell the servers the exact port to listen at. I keep getting port already in use issues though when I try to assign more than one server to a particular port. I don't know if this is even possible. Has anyone ever gotten this to work?

  • Several instances using same port question

    Good Morning,
    I am going to have to create several instances on one box using solaris 10 zone technology. Each zone haveing it's own instance. I need to confirm whether or not that all those instances can use one listerner or does each instance need it's own separate port such as 1521, 1522 etc. for it's listener.
    Your opinion and recommendation on this matter will be much appreciated.
    regards,
    al

    <br>> Good Morning,
    <br>>
    <br>> I am going to have to create several instances on one
    <br>> box using solaris 10 zone technology. Each zone
    <br>> haveing it's own instance. I need to confirm
    <br>> whether or not that all those instances can use one
    <br>> listerner or does each instance need it's own
    <br>> separate port such as 1521, 1522 etc. for it's
    <br>> listener.
    <br>>
    <br>> Your opinion and recommendation on this matter will
    <br>> be much appreciated.
    <br>>
    <br>> regards,
    <br>>
    <br>> al
    <br>
    <br>Hi,
    <br>
    <br>As you are going to be using Solaris Zones would you really want to have one listener for all of the instances?
    <br>
    <br>Surely the point of using Zones is separation of the environments so why would you want to try and break that by not having separate listeners? If you aren't interested in isolating the environments then Zones seems like an added headache you can do without.
    <br>
    <br>On the question of ports... each Zone is going to have its own IP address so it really doesn't matter what port you choose. They could all have the same port for their individual listeners or they could all have different ports. Makes no odds really.
    <br>
    <br>Hope that helps.

  • Help with 2 separate domains with the same ports in a single machine

    Hi,
    Where I can get info on having 2 separate domains on the same machine that works on the same ports, and one works with http://admin-server, and the other for http://production-server.
    I want to have webapps that are installed only in the admin domain, and the others in the production domain. The problem is that if I put the same ports for both domains says:
    Domain production-domain failed to startup. There is a conflict on port 80. Please check the server log for more details.
    CLI156 Could not start the domain production-domain.
    Thanks,
    Regards,
    Lorenzo Jim�nez

    Hi, we don't have two iPhones in the family as yet but as I understand it each device can have separate settings for syncing calendars and contacts. For example my iPhone syncs these over the air with the Exchange server at work so if/when my wife gets an iPhone it would be easy to have hers sync to Outlook on our computer
    To make sure apps purchased on one device don't inadvertently merge with others turn off Automatically sync new apps from the apps tab when you connect your device.
    The Apple support document How to use multiple iPods with one computer suggests a number of ways for managing the media content. I use method two (Sync with selected playlists) with a slight twist. Rather than regular playlists I set the grouping field to indicate which users should receive which tracks and create smart playlists based on the content of this field.
    e.g.
    "Alice's Tracks" is "Grouping contains Alice" + "Kind contains audio"
    "Bob's Videos" is "Grouping contains Bob" + "Kind does not contain audio"
    Tracks that both Alice & Bob want on their iPods have the grouping set to "Alice/Bob"
    etc.
    I currently manage our family's five iDevices using this system, each getting a different selection to suit their tastes and the capacity of their device. An advantage of using the grouping field is that it is stored in file tags (for non-wav audio files anyway) so that it is relatively easy to recreate the playlists should the iTunes library get trashed and need rebuilding. Also useful if you move files about manually as playlist membership is preserved when you delete & re-import the tracks.
    So far we have managed everything with a single Apple ID, but that will probably change as the kids leave home. Managing app updates from multiple IDs is a pain as you have to manually sign in to each account in turn, however there are other benefits to each user having their own account.
    tt2

  • Reading the same port on the same machine

    Hello,
    i'm working on DatagramSocket to broadcast DatagramPacket (IP 192.168.xxx.255) and a fixed num port. The problem is that I can't have 2 threads that read (datagramSocket.read) on the same port, on the same machine.
    How can I perform my tests ?
    java.net.BindException: Address already in use
    at java.net.PlainDatagramSocketImpl.bind(Native Method)
    at java.net.DatagramSocket.bind(DatagramSocket.java:368)
    at java.net.DatagramSocket.<init>(DatagramSocket.java:210)
    at java.net.DatagramSocket.<init>(DatagramSocket.java:261)
    at java.net.DatagramSocket.<init>(DatagramSocket.java:234)

    Well, the short answer is that you can't.... at least I've never heard of a way how. Basically, when an application requests a port number, it basically owns that port number until it gives it up. You do this when you create the DatagramSocket. Each DatagramSocket is its own request, and therefore must have an unique identifying port. Otherwise, how would your operating system know who to give the data to when it receives a packet on your machine for port XXXX? Also, it would be a secuirity problem if other applications could listen on the same port as you use for other things like surfing the web, making online purchases, email.
    However, what you could do is have one owner of the DatagramSocket... and share it among the other threads. When that owner receives a packet, it can notify the other threads it received a packet and pass the data to each one. Set it up something like how listeners work. Also, if you want it to span processes, you could use RMI or pass the data through other deined network connections between the processes.
    Does that make sense? :)

  • Installing 2x Instances of UCM on the same ports on a multihomed server

    We're looking at installing 2x instances of UCM on the same multihomed server, using the same port numbers for each.
    But following the initial installation, we note that the admin port binds to all of the IP's in the server.
    $ netstat -a | grep LISTEN | grep 444
    tcp 0 0 *:4440 *:* LISTEN
    Is there a way to stop the Admin server from doing this, and only to bind to a single IP ?
    We effectively want to get the 1st instance Admin Server to Listen on IP1:4440
    And the 2nd instance Admin Server to Listen on IP2:4440
    Same with port 4444 for both instances.
    Incidentally, the Admin Server should not really listen on all IP's by default, as this is a potential security risk especially if one IP was for example internal traffic, and the other one was for external traffic.
    So there are other reasons for not wanting to listen on all IP's within the server rather than the specific one.
    Any help / guidance much appreciated.
    Regards
    Andrew

    This configuration entry is available:
    IdcServerBindAddress=IPaddress
    It's generally been used in clustered installations but I see no reason why it wouldn't work with a stand alone instance as well.
    Regards,
    Josh

  • How to forward the same ports for multiple IPs?

    Hi all, I just bought a Linksys WRT54GS router and I would like to forward the same set of ports for two different computers on my network (192.168.1.101 and 192.168.1.3) however when I try to, I get a "Port Overlap" error. Is there another way I can do this? I am trying to set up Age of Empires II. Thanks for any help!

    No.  You cannot forward the same port to two different computers  (or IP addresses).  
    Here's the reason why:
    You and your friend are both playing the game online.  You score 1000 points.  Your friend scores 10 points.  The signal to increase your score 1000 points arrives on port 3078.  Which computer is the router supposed to send this signal to?  Both computers?   No way!
    Most online games have a way to assign different ports to different computers.  For example, you might use ports 3075 thru 3078, while your friend uses ports 3175 thru 3178.  If your game is setup this way, it should work.
    Also, you will want to forward ports to a fixed LAN IP address.  In your WRT54GS, note that any fixed LAN IP address must be outside the DHCP server range, and it cannot end in 0, 1, or 255.   So the 192.168.1.101  address is probably an illegal fixed LAN IP address.
    Here are all the Linksys rules for using fixed LAN IP addresses:
    With Linksys routers, a fixed (static) LAN IP addresses must be assigned in the device that is using the address. So you need to enter the fixed address in the computer or printer, not in the router.
    When using a Linksys router, any fixed LAN IP address must be outside the DHCP server range (typically 192.168.1.100 thru 192.168.1.149), and it cannot end in 0, 1, or 255.
    Therefore any fixed LAN IP address would normally need to be in the range of
    192.168.1.2 thru 192.168.1.99 or
    192.168.1.150 thru 192.168.1.254
    assuming you are still using the default DHCP server range.
    Also, in the computer, when you set up a static LAN IP address, you would need to set the "Subnet mask" to 255.255.255.0 and the "Default Gateway" to 192.168.1.1 and "DNS server" to 192.168.1.1
    It is also important that no two devices on your network be set to the same static LAN IP address.
    Typically, when I setup gamers, I put thier fixed addresses all together at 192.168.1.21 , 192.168.1.22, etc.   But you can use any legal fixed addresses that you want.

  • Two web servers cant use same port forwarding rule???

    I have two web servers, each configured to respond to http reqests on port 80.  I use NoIP service to map a domain name to my router. I create a port forwarding assignment for Server A by selecting the WebServer rule in the port forwarding rule table.  All is fine.  For Server B, I select the same Webserver rule and the router says there is a conflict.
    I don't understand why.  I think the router has enough information to route a http request for Server B by knowing its MAC address, which is different than Server A MAC address.
    What am I missing here???
    I was able to do this on my previous router with DD-WRT.....
    So it would appear the way to resolve this is to assign a different port address to Server B???
    grrrrrrrrrr I hate this router

    You shouldn't have been able to do that on any router.  You have to change the listening port of server 2, to 8080 or something like that, or make one a secure server and run it over 443
    That is a known issue with port forwarding
    Problem #8:
    Same Port in Multiple Rules
    There are some routers such as Linksys, D-Link and many others that do not do any checks if a port is already in another port forwarding rule. A port can only be forwarded to one Computer/IP at a time. So when there are multiples of the same port number the port forwarding rule will not work.
    Here is an example.
    As you can see port 2350 is in 2 rules. The 1st one points to a different IP than that of the 2nd rule. So the router will honor the 1st rule and the 2nd port forwarding rule to port 2350 fails.
    By removing the 1st rule the 2nd one will now work.

  • IDOC - XI - IDOC same port name in IDX1

    Hello,
    i have a problem in defining multiple receiver systems in IDX1.
    We have to send idocs to different system and some of them have the same SID.
    Receivers would have the same port name SAP(SID) ex : SAPPRD
    How could xi know which is the correct receiver port?
    Thanks,
    Laurent.

    Port name might be the same, but the RFC destination for each port is different. We use the the combination of port and RFC destination in communication also. Hence I guess there should not be any conflict.
    I may be wrong here. Correct me if am wrong.
    Regards,
    Jai Shankar

  • How to Send & receive HL7v2.3 & HLv2.5.1 message from same port.

    Hi,
    Currently I have a requirement of sending multiple version HL7 messages say HL7v2.3 & HLv2.5.1 from the same port(say 3333) and receive it at the same port (say 4444) using Oracle SOA Suite.
    To address this problem, I first tried to create multiple versions endpoints in the Healthcare UI of SOA and gave them separate Composites each catering different versions of the HL7 message structure. But this didn't work since, the Healthcare UI refuses to accept two different Composites. Not sure if this supported in Healthcare UI or not?
    Also, another problem which this approach threw at me was that I have another challenge to create a single healthcare adapter to accept both versions which is not possible, i think, because when we are creating the HL7 adapter in the Composite it asks to provide the HL7 structure it follows and there can be only one message structure that I could provide to this healthcare adapter placed at the receiving end.
    With extensive googling I was pointed out to second approach of making it entirely in B2B. But there was also stuck at the time the agreement (Agreement between local partner and remote partner for both the HL7 versions) was to be deployed, since it was giving this error.
    Agr1 is not valid. Please correct the following errors.
    Error -: B2B-52276: Type of the parameter MessageECSFileBlob must match with the value {1}
    On my part I tried to investigate what this MessageECSFileBlob is?
    And the answer I got is that it is part of Document Definition and is  "Absolute file path of ecs".
    My Take & Confusion Around this::
    1. Since I first tried to cater this problem through Healthcare UI so, I have imported the repository for both the versions HL7v2.3 & HLv2.5.1. Now since the B2B shows all the HL7 versions, therefore I didn't create any custom message structure for this since the entire HL7 version repository is already available to me.
    Do I need to remove these versions from the repository and come back to B2B to first provide it custom message structure for both HL7v2.3 & HLv2.5.1?
    2. Any idea if one endpoint can support multiple message structure with different composites in Healthcare UI?
    Thanks
    Saurabh

    Hi citbcj,
    You could "fix" by catching and handling the exception. Here's the pseudo code
    declare
      exception   smtp_error;
      pragma exception_init (smtp_error, -29279);
    begin
      for rec_notify in cur_notify loop
        declare
          l_to   varchar2 (100) := rec_notify.email;
        begin
          html_email (l_to, l_from, l_subject, 'none', l_body);
        exception
          when smtp_error then
            log_it_or_something_and_continue;
        end;
      end loop;
    end;
    /Regards
    Peter

  • Open a several sessions in the same port 22224

    i want to receave a severel streams from 3 PC in the same port 22224 using a several sessions of this port(22224). it's possible?and how?
    how i can know the source of the sender of stream (ip adresse for exemple)?.
    thinks a lot.

    <SCRIPT language="JAVASCRIPT">But this is a Java forum, not a Javascript forum.

Maybe you are looking for