How to write a socket in that i have to use an array of ports

dear all
Iam doing project in java in that iam using sockets. My problem is i want to keep array of ports in my programming. suppose one port is busy then it automatically take the other port in the array of ports. Please can any body give me the solution how to use that one. Or if any body know any site regrding that please send me. Ill be waiting for your rely.
regards
sonali

Hi Sonali,
You can use this. To test,
javac Sockets.java
java Sockets &
java Sockets &
Here I have used only 3 entries in the array. Server sockets bind and and then listen on them. This is for server sockets. You can write the client side part which will be similar to this.
Hope it helps.
Regards,
Giridhar
import java.net.*;
public class Sockets
ServerSocket socket = null;
int ports[];
int counter;
public Sockets()
counter = 0;
ports = new int[3];
ports[0] = 1000;
ports[1] = 1900;
ports[2] = 12000;
public ServerSocket bindSocket()
int backLog = 50;
try
socket = new ServerSocket(ports[counter], backLog, InetAddress.getByName("localhost"));
System.out.println("server socket bound successfully at port " + ports[counter]);
return socket;
catch(BindException e)
System.err.println("Port " + ports[counter] + "is busy, trying with " +
ports[++counter]);
if (counter == ports.length)
System.out.println("Could not succeed with any port, returning null");
return null;
return bindSocket();
catch(UnknownHostException uhe)
System.err.println("wrong host name");
return null;
catch(java.io.IOException ioe)
ioe.printStackTrace();
return null;
public static void main(String[] args)
Sockets sockets = new Sockets();
ServerSocket ss = sockets.bindSocket();
try
while(true)
Socket acc = ss.accept();
System.out.println("client accepted, break");
break;
System.out.println("tested, now closing the socket");
ss.close();
catch(java.io.IOException e)
System.err.println("io exception while closing socket");

Similar Messages

  • How do I activate Office 2013 that I have deployed using ODT and App-V onto a Remote Desktop Server?

    I am setting up a demo Server 2012 R2 environment (1 DC server, 2 RDSH servers, 1 App-V server).
    I have created an Office 2013 volume license App-V package using the latest Office Deployment Toolkit. I have deployed the App-V package to an RDS server and it all works fine. However, I am unable to activate Office 2013 using the MSDN Office 2013 retail
    key because it tells me the product key is invalid for this version of Office. I've looked at the alternative of using the App-V Sequencer to create the Office 2013 package, but from what I've read this is not a Microsoft supported method.
    Is there any way that I can activate Office 2013 (volume license on RDS) using the method I've outlined above, or is there any way of using the Office2013 download from MSDN such that it can be packaged by the ODT (or App-V Sequencer) for successful deployment
    using App-V and activation using the retail Office 2013 product key on MSDN?

    True, VL channel media can't be activated with MSDN Retail pkeys (that's what I was trying to get you to understand, I figured you would be attempting that, as so many people do :(
    I've not attempted your scenario myself.
    It sounds like you aren't following the supported scenarios as (poorly) described by MS;
    The way I read their guide, for an RDS scenario, you must use a VL key [either MAK or KMS] (since a subscription product+key can't be used on RDS):
    i.e.: <Product ID="ProPlusVolume">
    http://support.microsoft.com/kb/2772509
    http://support.microsoft.com/kb/2915745
    http://technet.microsoft.com/library/dn481351.aspxhttp://blogs.technet.com/b/office_resource_kit/archive/2013/12/02/announcing-app-v-5-0-sp2-support-for-office-2013-volume-licensing-editions.aspx
    So, that all means that for RDS, you can't use anything other than VL "product" (in
    the form of an ODT-generated output) with a VL pkey. So, for your RDS demo setup, you need to use real product and real pkeys.
    Don
    (Please take a moment to "Vote as Helpful" and/or "Mark as Answer", where applicable.
    This helps the community, keeps the forums tidy, and recognises useful contributions. Thanks!)

  • Need to write on a document that i have received via email.  how do I do this??

    how do i enable a document that i have accessed on line so that i can write on it?????

    What type of document are you attempting to sign?  Is it a PDF? A Word document? Something else?
    Do you have the document on your computer?

  • I have an old ipod that i have not used in a very long time, ive had it on a charger now for over an hour and i still cnnot get my ipod to turn on, how can i fix my problem, i just downloaded the new version of itunes aswell, so i know its not my itunes.

    i have an old ipod touch that i have not used in a very long time, and im having trouble gettign it to turn on. ive had it on a charger for over an hour now and still nothing hs changed. i just updated my itunes to the current version they haev so i know its not an itunes problem its rather a problem with the old ipod touch itself. im leaving for deployment soon and im trying to get this fixed without having to send it in. If anyone has any ideas on how to get this thing turned on it would be greatly appreciated.

    Well, two thoughts.
    The battery has completely discharged and will take overnight to recharge, so don't expect much in an hour.
    The battery has deep discharged and is now dead. It will never recharge and should be replaced.
    If your iPod Touch, iPhone, or iPad is Broken
    Apple does not fix iDevices. Instead they exchange yours for a refurbished or new replacement depending upon the age of your device and refurbished inventories. On rare occasions when there are no longer refurbished units for your older model, they may replace it with the next newer model.
    You may take your device to an Apple retailer for help or you may call Customer Service and arrange to send your device to Apple:
    Apple Store Customer Service at 1-800-676-2775 or visit online Help for more information.
    To contact product and tech support: Contacting Apple for support and service - this includes international calling numbers.
    iPod Service Support and Costs
    iPhone Service Support and Costs
    iPad Service Support and Costs
    There are third-party firms that do repairs on iDevices, and there are places where you can order parts to DIY if you feel up to the task. Start with Google to search for these.
    The flat fee for a battery exchange is, I believe, $99.00 USD.

  • My email address has changed and when I try to play purchased songs it asks me to authorize another computer under the old email address.  How do I play the music that I have purchased?  My account is current with the new email address.

    My email address has changed and when I try to play purchased songs it asks me to authorize another computer under the old email address.  How do I play the music that I have purchased?  My account is current with the new email address.

    You may have already done this, but try de-authorizing your computer (through the iTunes:Store menu) and then re-authorizing it.

  • I was on a free dictionary website and it asked me if it would like to send me push notifications and i allowed it but i don't want them anymore...how do i get rid of that? I'm using my macbook pro by the way

    I was on a free dictionary website and it asked me if it would like to send me push notifications and i allowed it but i don't want them anymore...how do i get rid of that? I'm using my macbook pro by the way

    Go to the site and look for an unsubscribe link. Or, contact the site and ask them to stop.

  • I have an old Ipod 5th gen that I have been using for downloading music from my library.  Upon purchasing an Ipod touch and registering it in Itunes, I can no longer sync tunes to my old ipod.  How can I get that option back on my old ipod?

    I have an old Ipod 5th gen that I have been using for downloading music from my library.  Upon purchasing an Ipod touch and registering it in Itunes, I can no longer sync tunes to my old ipod.  How can I get that option back on my old ipod?

    - iTunes purchases by maybe
    iTunes Store: Transferring purchases from your iOS device or iPod to a computer
    - For other music you need a third-party program like one of those discussed here:
    newer copy
    BTW, this is the iPod touch forum.

  • HT4743 how do i transfer a film that i have purchased on my apple TV to icloud so that i can strem from either my PC/IPAD/Ipod or apple TV

    How do i move a film that i have purchased on apple TV to Icloud so that i can stream from my ipad/ipod or PC?
    Thanks

    The movie is already in iCloud.
    The 2nd and 3rd Gen ATVs have virtually no local storage and do not store any content.  There is nothing to transfer from the device.
    Simply download the content to the desired devices.

  • How I can erase the components that I have created in a content area?

    hello. Somebody knows how I can erase the components that I have created in a content area. I have created an area of content and the archives, categorias or perspective that I generate not let erase. The same it happens to me to the forms, reports and other components created under a certain application

    goto portal navigator --> content areas --> next to the content area --> click Edit Properties --> Items tab --> last button on the page is Purge..
    this should take care of it

  • How do I change a document that I have saved as a PDF file in Documents? I can get it to OPEN but can't do anything to it.

    How do I change a document that I have saved as a PDF file in Documents........I can open it but can't do anything with it.

    A PDF is really an electronic print of your document & is not intended for future editing. You should always save a copy of the original document in the program that created it & use that for edits. You can then export or print the revised document to PDF, again saving the original.

  • How do I delete Pages templates that I have created?

    How do I delete Pages templates that I have created?

    Pages stores those you created & saved as templates in (your account) > Library > Application Support > iWork > Pages > Templates > My Templates. The user's Library is hidden in Lion & Mountain Lion but it is easy to open. In Finder, hold down the Option key while clicking on the Go menu & your user Library will appear about halfway down the list. Or you can choose Go to Folder from the Go menu in Finder & paste this line in the box:
    ~/Library/Application Support/iWork/Pages/Templates/My Templates/

  • How do I save a jpg that I have in photoshop elements as a high-res or vector format.

    how do I save a jpg that I have in photoshop elements as a high-res or vector format.
    thanks

    Welcome to the forum.
    I wonder, however, if you meant to post to the Photoshop Elements Forum, and not to the Premiere Elements (Video editing program) Forum?
    If you want PSE, then see the above link.
    To Save_As uncompressed, you might want to look at PNG for the format.
    Good luck,
    Hunt

  • How to write an xml Document to a flat file using JAVA....

    Can any one help me out.....
    How to write a XML Document to the current filesystem using JAVA....
    without using com.sun.xml.tree.*....
    Document xmlDoc;
         Node rows = (Node) xmlDoc.createElement("ROWS");
    xmlDoc.appendChild(rows);
    and i have to write this xmlDoc to a file called(abc.xml) for further use...

    Have you considered using JDOM? ( www.jdom.org )
    The XMLOutputter class can write the Document to a file. ( The Document however will be an org.jdom.Document object ).
    If you are weary of a new API, you could just create a new File object called abc.xml and stream the data from the XML Document you have to this new File object.

  • How do i get music on that i have put on itunes off a cd on to my iphone 3gs with ios 5.1?

    how do i get music on that i have put on itunes off a cd on to my iphone 3gs with ios 5.1?

    Post by Zevoneer: iPod media recovery options - https://discussions.apple.com/message/11624224 - this is an older post and many of the links are also for old posts, so bear this in mind when reading them.
    Commercial software utilities for transferring songs from i-device to Mac:
    Senuti - http://www.fadingred.com/senuti/
    Phoneview - http://www.ecamm.com/mac/phoneview/
    MusicRescue - http://www.kennettnet.co.uk/products/musicrescue/ - Mac & Windows

  • How i can install the products  that i have in my contract on my laptop?

    how i can install the products  that i have in my contract on my laptop?

    Make sure your laptop meets the system specifications for the software.  Then download and install the CC manager program, sign in using your authorization code, and install the programs that your contract supports.

Maybe you are looking for

  • Very slow broadband in Greenwich area

    Hi, My broadband speeds fell off a cliff recently. Been noticing disconnects in recent weeks, now getting speeds of about 350k upload on a line capable of 6.5mb. Help line is useless - tried to diagnose my wifi despite my explaining I was looking at

  • Make Flash CS5.5 Movie play through one time

    I have created a movie in Flash Professional CS5.5 which has two scenes in it, and I want iot to only play through a single time and then stop.... I opened it originally as a Flash Project, completed the first scene which was an opening screne with a

  • North of England Outage

    Let's start from the dual premise that: a) I'm not a cretin; and b) I do have a working knowledge of IT. A summary of my latest issue (there are always problems with BT but I've no alternative except carrier pigeon): - About 18 hours ago BB speed dro

  • Single node Dataguard setup

    Please can somebody provide me the source for step by step single instance physical standby dataguard setup for my single instance database.

  • Abstract classes and Constructors

    I am wiondering how can an Abstract class have a constructor? Won't the constructor of the derived class automatically invoke the constructor of Shape by calling super()implicitly That means that an object of type Shape has been created Or have I ove