Can i use the same socket to connect to more than one servers

hi,
I'm new to java. I want to know whether a socket created using Socket() constructor can be used to connect to multiple servers, not necessarily at a particular point of time. ie, i want to connect to various servers using a single socket and register some info abt them, possible using a loop, one by one. I use connect() method to connect to particular server.
In other words is Socket class is mutable.
Edited by: itsraja on Feb 25, 2008 5:50 AM

In short, I don't think so.
Setting the server name for a socket is in the constructor.
Socket s = new Socket("localhost", 501);I don't believe that there are any functions, such as:
s.setHost("localhost");
s.setPort(501);However, JavaDocs suggests that when you use the no-args constructor, your class becomes an automatic SocketImpl class, but you can't reach any of its variables unless you derive from the class, itself. But that's probably a bigger headache than it's worth.
Now TECHNICALY, if you didn't want to create a new variable, you could use:
Socket s = new Socket("localhost", 501);
s.close();
s = new Socket("remotehost", 502);
s.close();However, this is still creating a new instance and thus a new object in memory.
I hope this answers your question.
Let us know exactly what you're trying to do for a more exact answer.
~Derek

Similar Messages

  • How can i use the same front panel graph in more than one events in an event structure?

    i want to display the signals from my sensorDAQ in a graph.but i have more than one event in the event structure to acquire the signal and display it in the graph.the first event is to acquire the threshold signals and its displayed in the graph as a feedback.after the first event is executed, i will call the second event,where the further signals are acuired and compared with the threshold signals from the event 1.my question is how can i use the same front panel control in more than two events in the event structure?please answer me i'm stuck.
    Solved!
    Go to Solution.

    Hi,
    I have attached here an example of doing the same using shift registers and local variables. Take a look. Shift register is always a better option than local variables.
    Regards,
    Nitzz
    (Give kudos to good answers, Mark it as a solution if your problem is Solved) 
    Attachments:
    Graph and shift registers.vi ‏12 KB
    graph and local variables.vi ‏12 KB

  • Can I use a single QuickTime Pro key on more than one computer?

    I would like to use QuickTime Pro at both home (Windows Vista) and at work (Windows XP). Can I do this using a single purchased key, or do I need to buy two separate keys, one for each machine?
    It's a rather stupid question, but I can't find an straightforward statement one way or the other in the FAQs. Perhaps the answer's too obvious!
    Cheers,
    Andrew.

    Thanks! I thought this would probably be the case, but since iTunes allows me to authorise more than one machine, I thought that it was just possible that QuickTime might do the same. Back to the drawing board ...
    Cheers,
    Andrew.

  • Use a skype number nd connect to more than one sky...

    can i use a skype number and connect this to more than one skype account. or can i create a group of skype accounts who can pickup the call?

    no, a Skype Number is linked to a single Skype Name
    calls to a Skype Name can, however, be forwarded to as many as three other numbers or Skype Names -- whoever answers first gets the call
    incoming Skype calls can only be forwarded once using Skype
    http://www.skype.com/en/features/call-forwarding/
    Regards,
    Neil

  • Can I split the screen in Adobe to show more than one ducument at the same time? ie. view three different documents on one screen

    I am trying to look at three Adobe documents at the same time.  Can I split the screen to do this, otherwise I must keep flipping back and forth to read the documents.

    You can arrange the open windows in any way that suits you (assuming you're on Windows - not Touch - or Mac). You can't link the scrolling though.

  • Can I split the output of my airport to more than one device?

    I have an apple airport connected to my stereo.  This allows me to listen to my itunes library over my household stereo.  I want to hook up a second stereo, with speakers in a different room.  Can I split the RCA outputs so that it goes to a second stereo?

    bayfish,
    edex67 is right that a second AirPort Express would do the trick. It would have the advantage that you could select from the Mac which stereo got the signal, and you could even drive separate signals to the two stereos should you (or your guests) have a second AirPlay source.
    If you want to try the splitter idea, it would likely be cheaper than another Express, but don't buy the cheapest cable, especially for the long run to the second room. If you have the inaudibility problem that edex67 mentioned, you can try turning up the volume on the stereo(s)..

  • Express won't connect to more than one devise

    I got an airport express used and it won't connect to more than one device. First only my MacBook and would not allow my iPad on. And now the playstation is connected and the MacBook can't get Internet. Any advise?

    Kyle-BHD wrote:
    I got an airport express used and it won't connect to more than one device.
    Please identify the model number of your AirPort Express (A1084, A1088, A1264?), the brand(s) and model number(s) of your other networking equipment, and how it's all connected. When you launch AirPort Utility and put the AirPort Express into "manual setup" mode, what value do you see for "Connection Sharing" in the Internet panel, "Internet Connection" tab?

  • Need to connect to upgraded Oracle EBS R12 version from R11. The current ODI set up is pointing to R11, Can i use the same connection to point to R12? Please hele experts..

    Need to connect to upgraded Oracle EBS R12 version from R11. The current ODI set up is pointing to R11, Can i use the same connection to point to R12? Please hele experts...
    Rp

    1. in physical connections part can i use the same work schema
    2. Can i use same contexts created or do i need to create everything as new and then try?
    Thanks,
    Rp.
    Hi,
    As you mentioned that you just upgraded the database, so the data is same and schema is same you can connect with the same work schema.
    Yes, you can use the same contexts , but need to do Reverse Engineering for your new database.
    And about data server, i think you also have no need to create new data server, if hostname,sid and port etc are same as these were with R11(consult with your DBAs regarding it)

  • Can I use the "same" button multiple times for multiple galleries?

    OK so I am extremely untrained in CS4 and Actionscript. However I have managed to get along fairly well until I started to dynamically upload images as a gallery. This works great if I have one gallery, but for my site I have 9 galleries!!! I have a back and next button, but I want to be able to use those same buttons for all of the galleries so they look the same. I have split them up and renamed them, but I am clueless on how to script the buttons to work. Please help...and don't laugh at my poor scripting. This is what I have now because I do not know where to put the other button names without getting errors.
    stop();
    next_btn .addEventListener(MouseEvent.CLICK, nextImage);
    var imageNumber: Number=1;
    function checkNumber(): void{
        next_btn.visible=true;
        back_btn.visible=true;
        if(imageNumber==15){
            trace(imageNumber);
        next_btn.visible=false;
        if(imageNumber==1){
            trace(imageNumber);
        back_btn.visible=false;
    function nextImage(evtObj:MouseEvent):void {
        imageNumber++;
        mc_engagement.source= "photo/engagement/en0"+imageNumber+".jpg";
        mc_amish.source= "photo/amish/Amish"+imageNumber+".jpg";
        mc_chicago.source= "photo/chicago/ch"+imageNumber+".jpg";
        mc_landscapes.source= "photo/landscapes/land"+imageNumber+".jpg";
        mc_goodvsevil.source= "photo/goodvsevil/ge"+imageNumber+".png";
        mc_animals.source= "design/animals/an"+imageNumber+".png";
        mc_icons.source= "design/icons/icon0"+imageNumber+".png";
        mc_objects.source= "design/objects/pc"+imageNumber+".png";
        mc_typography.source= "design/typography/type"+imageNumber+".png";
        checkNumber();
    back_btn .addEventListener(MouseEvent.CLICK, backImage);
    function backImage(evtObj:MouseEvent):void {
        imageNumber--;
        mc_engagement.source= "photo/engagement/en0"+imageNumber+".jpg";
        mc_amish.source= "photo/amish/Amish"+imageNumber+".jpg";
        mc_chicago.source= "photo/chicago/ch"+imageNumber+".jpg";
        mc_landscapes.source= "photo/landscapes/land"+imageNumber+".jpg";
        mc_goodvsevil.source= "photo/goodvsevil/ge"+imageNumber+".png";
        mc_animals.source= "design/animals/an"+imageNumber+".png";
        mc_icons.source= "design/icons/icon0"+imageNumber+".png";
        mc_objects.source= "design/objects/pc"+imageNumber+".png";
        mc_typography.source= "design/typography/type"+imageNumber+".png";
        checkNumber();

    I'm still a novice with Flash myself, but I have two comments.
    First, at this point, won't your buttons control all galleries at the same time? Which means, if I go to image 5 in one gallery, then move to another gallery, I'll start at image 5, because the actions are all connected.
    Second, you can definitely use the same buttons for multiple galleries. It seems to me that as long as you've assigned the buttons an instance name, these actions should already work to control all the galleries (see the note above). I guess I would need to understand a bit more about how your project is built.

  • Can you use the same charging cable for both an iPhone and an IPad or are they different?  When I use the charging cable for my iPhone on my Ipad, it doesn't charge.

    Can you use the same charging cable for both an iPhone and an IPad or are they different?  When I use the charging cable for my iPhone on my Ipad, it doesn't charge.

    The quickest way (and really the only way) to charge your iPad is with the included 10W USB Power Adapter. iPad will also charge, although more slowly, when attached to a computer with a high-power USB port (many recent Mac computers) or with an iPhone Power Adapter (5W). When attached to a computer via a standard USB port (most PCs or older Mac computers) iPad will charge very slowly (but iPad indicates not charging). Make sure your computer is on while charging iPad via USB. If iPad is connected to a computer that’s turned off or is in sleep or standby mode, the iPad battery will continue to drain.
    Apple recommends that once a month you let the iPad fully discharge & then recharge to 100%.
    How to Calibrate Your Mac, iPhone, or iPad Battery
    http://www.macblend.com/how-to-calibrate-your-mac-iphone-or-ipad-battery/
    At this link http://www.tomshardware.com/reviews/galaxy-tab-android-tablet,3014-11.html , tests show that the iPad 2 battery (25 watt-hours) will charge to 90% in 3 hours 1 minute. It will charge to 100% in 4 hours 2 minutes. The new iPad has a larger capacity battery (42 watt-hours), so using the 10W charger will obviously take longer. If you are using your iPad while charging, it will take even longer. It's best to turn your new iPad OFF and charge over night. Also look at The iPad's charging challenge explained http://www.macworld.com/article/1150356/ipadcharging.html
    Also, if you have a 3rd generation iPad, look at
    Apple: iPad Battery Nothing to Get Charged Up About
    http://allthingsd.com/20120327/apple-ipad-battery-nothing-to-get-charged-up-abou t/
    Apple Explains New iPad's Continued Charging Beyond 100% Battery Level
    http://www.macrumors.com/2012/03/27/apple-explains-new-ipads-continued-charging- beyond-100-battery-level/
    New iPad Takes Much Longer to Charge Than iPad 2
    http://www.iphonehacks.com/2012/03/new-ipad-takes-much-longer-to-charge-than-ipa d-2.html
    Apple Batteries - iPad http://www.apple.com/batteries/ipad.html
    Extend iPad Battery Life (Look at pjl123 comment)
    https://discussions.apple.com/thread/3921324?tstart=30
    New iPad Slow to Recharge, Barely Charges During Use
    http://www.pcworld.com/article/252326/new_ipad_slow_to_recharge_barely_charges_d uring_use.html
    Tips About Charging for New iPad 3
    http://goodscool-electronics.blogspot.com/2012/04/tips-about-charging-for-new-ip ad-3.html
    Prolong battery lifespan for iPad / iPad 2 / iPad 3: charging tips
    http://thehowto.wikidot.com/prolong-battery-lifespan-for-ipad
     Cheers, Tom

  • Can I used the same MSN  with Windows and Mac?

    I have a emachine PC. And I just purchase a ibook G4. My concern is: I am about to connect to the internet witn MSN. Can i used the same with both, Mac and Windows? I mean, the same internet connection?
    LightBearer.

    All you'll need is a router. You can get a wireless one or a wired one. They're pretty cheap.

  • I'm in the trial period for Creative Cloud - I have about 19 days to go on Photoshop CC on my iMac.  Can I use the same CC trial on a second machine?  Specifically on a Windows 7 machine?

    I'm in the trial period for Creative Cloud - I have about 19 days to go on Photoshop CC on my iMac.  Can I use the same CC trial on a second machine?  Specifically on a Windows 7 machine?

    Nothing personal to you or Rajshee, but this is exactly why I absolutely despise these "community forums" (not just Adobe but any company).  I called the Tech Support phone line today after digging and digging for a phone number, and they told me the exact opposite, and they did it a lot faster than it was possible to get a forum response.  (That's really not personal, because you can't control that, but it's a fact.)
    Their answer: As long as I'm signed in with the same ID, I can try, say, Photoshop CC on my iMac at home and also try Acrobat Pro CC on my Windows 7 machine at work.  Same account, same login, one trial.
    This makes complete sense to me as I'm financially on the hook (potentially) for the same package.  If I give away my login to someone else, which I wouldn't do, I'm still on the hook.  This is why the cloud approach to software is such genius and I applaud it.
    BTW, 99% of the "community forum" wrong answers come on Microsoft sites, so don't feel bad. 

  • Can you use the same Apple ID on more than one MacBook Pro for updates and applications?

    We just got a few new MacBook Pro's and when I went to install updates it said I need to make an Apple ID.  Can you use the same Apple ID and email address for that Apple ID on multiple machines, or do I need them both to be unique per machine?  I'm not sure how that works when you have multiple machines.

    An Apple ID is a user name you use for everything you do with Apple. Creating an account for an Apple service, such as the iTunes Store or the App Store, creates an Apple ID. Apple ID allows you to access other Apple services.   So you can use the same Apple ID for up to 10 Macs associated with it.
    To create an Apple ID you need to enter  your full name and your primary email address as your Apple ID. This will be used as the contact email address for your account.

  • How many times can you install Lightroom 5? My problem is that I have saved my programs on C. To I have more space, I want to save my programs now on E. Can I now uninstall Lightroom and reinstall from C to E? Can I use the same license code as the first

    Please help!!
    How many times can you install Lightroom 5? My problem is that I have saved my programs on C. To I have more space, I want to save my programs now on E. Can I now uninstall Lightroom and reinstall from C to E? Can I use the same license code as the first installation?

    Thank you for your answers, it helps me a lot.
    But sorry for my ignorance. I understand how you mean it, but I don't know how to do it. I'm scared to lose the settings/edits of the images.

  • I already have adobe digital editions on my mac pc and download books from the library to my android e-reader. Can I use the same digital editions on my ipad air, or do I need to load a different one onto my ipad?

    I already have adobe digital editions on my mac pc and download books from the library to my android e-reader. Can I use the same digital editions on my ipad air, or do I need to load a different one onto my ipad?

    Try following forum:
    Adobe Digital Editions

Maybe you are looking for