Can't send and receive on the same port

Hello,
I have a socket client which send a message to serverSocket then it should wait for a response.
The problem I have is that the client send the message but when it tries to open a connection as socketserver on the same port it can't , a have this ERROR CannotGetConnectToTheHost
this is the code of my client :
try {
echoSocket = new Socket("localhost", 3001);
out = new PrintWriter(echoSocket.getOutputStream(), true);
out.println(hdr + testContent );
echoSocket.getInputStream()));
} catch (UnknownHostException e) {
          System.err.println("Don't know about host: localhost.");
          System.exit(1);
} catch (IOException e) {
     System.err.println(
          "Couldn't get I/O for "
     + "the connection to: USE host : "
          + e.toString());
          System.exit(1);
     out.close();
     echoSocket.close();
int compteur = 0;
try {
ServerSocket oreille = new ServerSocket(4001);
Socket socket = (Socket)null;
System.out.println("Ready to accept connections");
while (true) {
     socket = oreille.accept();
     System.out.println("\n Nouveau message r�ceptionn� :\n");
     InputStream entree = socket.getInputStream();
     int c;
     String msgAdh = "";
     while ((c = entree.read()) != -1) {
     msgAdh += (char) c; //lecture byte par byte
     compteur++;
     System.out.println("Ready to accept Another Message ");
     entree.close();
     socket.close();
     oreille.close();
} catch (IOException e) {
System.out.println("CannotGetConnectToTheHost");
thinks in advance

When printing out an exception, print the exception object too, e.g.System.out.println("..whatever...:" + e); It almost always contains useful information. For extra credit, print out the stack trace too.
If I understand correctly what the program does:
    while (true) {
        socket = oreille.accept();
        oreille.close();
    }That can't be right: after the first loop, you close the socket, and then try to use it again on the second loop. If you want to keep using a socket, keep it open.

Similar Messages

  • How can we send and receive voice in same program

    Please can any one suggest me how to send and receive voice in the same program. I want both AVTransmit & AVReceive in the same program i tried it but its too difficult to do it.. Any one has got that code? And also i want my program to know if any third person is wanting to call me.. I mean how to recognise a new call. Please relpy to the following mail id.. Please i need it urgently..
    [email protected]

    Sir please execute this code.
    printf("I need it ");
    for(i=0;i<=infinity;i++)
    printf("V E R Y ");
    printf("U r g e n t");
    Now Please Send it to me sir.Please..Does not compile!

  • Sender and receiver on the same server

    Good morning!
    We plan a TDTIM for 2 different SIDs but with their Oracle DBs on the same server (NOT MCOD).
    If we use them as the sender and receiver respectively, any concern about the performance?
    Any other concerns?
    We know that TDMS within the same SID but different clients is NOT recommended.
    Our TDMS server is on a seperated box.
    Thanks for sharing your experience.

    As the hardware resources will be shared, you need to make sure -
    > the box has optimum resources to handle large data transfer volume.
    > the system and DB parameters are set correctly. There is a note to suggest these setting for high volume data transfer.
    > avoid two data intensive steps to run in parallel, for example do not run receiver deletion and data selection in parallel.

  • Can IDoc sender and receive system be the same client?

    thanks.
    I think one client can't assign to two logical system.so?

    <i>Can IDoc sender and receive system be the same client?</i>
    yes
    Regards,
    Prateek

  • TS2755 Why I can't send and receive MMS with Redpocket on the 4s,iOS 5.1.1?

    Why I can't send and receive MMS with Redpocket on the 4s,iOS 5.1.1?

    Check Settings>Messages>MMS Messaging and make sure it's set to on. Contact Redpocket and make sure your account is provisioned correctly. However, if Redpocket is not a supported carrier, it is possible that not all functions of the iPhone will work or work as expected.

  • I changed my carrier , i can't send and receive any sms any call, i erase my data and after the problem still..ifone 4S ios 8.3..thank u

    iPhone 4S 16 Gb
    iOS 8.3
    I change my carrier , I can't send and receive any sms any call
    I erase my data .,after the problem still again
    can you help me please ?
    thank u

    thank u
    but when I make my sim card in another phone it work normaly.and when I make another sim card in my fone the problem still and I can't send
    have you another solutions ?

  • Can I send and receive e-mails on my iPad through Verizon?

    Can I send and receive e-mails on my Ipad (third generation) the same as I do on my iPhone 4s? Both are through Verizon. And if I can, where do I set it up at? Thanks.

    Yes. Why couldn't you use the same email account?
    Settings>Mail, Contacts, Calendars>Add Account>Other. Start there.

  • Can't send and receive text messages

    Hello,
    For around 2-3 weeks I can't send and receive text messages. When I try to text somebody, the message appears as "Not delivered". On the ! there are only 2 options: Try again and Cancel. If I choose to "Try again", the results is the same: the message is not delivered.
    When somebody is trying to text me, the message appears as delivered on their phone, but does not reach mine.
    Please advice
    Regards
    Irina

    Yes, I contact them and the problem was on their side. Now my problem is solved

  • On my iPad I can only send email and messages to apple products.how can I send and receive from other devices other than Apple?

    On my iPad I can only send email and messages to apple products.how can I send and receive from other devices other than Apple?

    Vallakat wrote:
    On my iPad I can only send email and messages to apple products.
    There is a huge difference between sending email and sending messages.
    Yes, I believe you when you say you can only send messages to other Apple products.  The iPad is not a telephone, and therefore, it cannot text message.  It can only iMessage, which means it can send and receive messages to/from other Apple products if they are on WiFi or an iMessage capable cellular network.
    Email, however, is a whole different category.  I don't really think you can only exchange email with other Apple products only.  Make sure you have correctly identified the symptoms.

  • Help!!! My text application on Blackberry Torch 9800 disappeared!!! I can't send and receive texts :-(

    Hi everyone,
    I need your help!!!
    The application to send and receive text does not appear on my phone Blackberry 9800 anymore... So, I can't send and receive texts...
    I tried lots of things but the problem is still existing.
    I have one error message everytime I turn on and reset the phone: "Uncaught exception: Index 14 >= 14" !!!
    Any idea of what to do???
    Thanks
    Rachel

    Hi and Welcome to the Community!!
    There's pretty much no diagnosing those -- they are the equivalent of the random errors in Windows for which tracing the root cause is fruitless. Basically, these are the last out in the programming code -- some event occurred for which there is no handler in the code. The fix is a code update that handles the event...but, again, knowing what the event is is pretty much impossible. So, there are a few things to try:
    Sometimes, the code simply becomes corrupt and needs to be refreshed -- just like a reboot:
    Anytime random strange behavior or sluggishness creeps in, the first thing to do is a battery pop reboot. With power ON, remove the back cover and pull out the battery. Wait about a minute then replace the battery and cover. Power up and wait patiently through the long reboot -- ~5 minutes. See if things have returned to good operation. Like all computing devices, BB's suffer from memory leaks and such...with a hard reboot being the best cure.
    If it won't boot up cleanly, then you may need to try Safe Mode:
    KB17877 How to start a BlackBerry smartphone in safe mode
    There might be an updated code set from the carrier -- check them via this portal:
     http://na.blackberry.com/eng/support/downloads/download_sites.jsp
    The toughest possible cause is a badly behaving app. To find it, there are a couple of options. One is to see if you can read the log file:
    Go to the home screen. Hold down the "alt" key and type 'lglg'. (You will not see anything while you type).This will bring up the log file. Scroll down (probably many pages) untill you see a line that says 'uncaught execption'. Click on this line. The name of the app will be in the info. Alternative methods for bringing up the logs are in this KB:
    KB05349How to enable, access, and extract the event logs on a BlackBerry smartphone
    The other method is to remove apps one at a time, waiting a while in between (I usually recommend a week), until the problem ceases...thereby discovering the offending app. Still another method is to reload the BB OS cleanly, leaving some time between adding other apps onto the BB so as to be able to determine exactly which one is the cause.
    Good luck and let us know!
    Occam's Razor nearly always applies when troubleshooting technology issues!
    If anyone has been helpful to you, please show your appreciation by clicking the button inside of their post. Please click here and read, along with the threads to which it links, for helpful information to guide you as you proceed. I always recommend that you treat your BlackBerry like any other computing device, including using a regular backup schedule...click here for an article with instructions.
    Join our BBM Channels
    BSCF General Channel
    PIN: C0001B7B4   Display/Scan Bar Code
    Knowledge Base Updates
    PIN: C0005A9AA   Display/Scan Bar Code

  • How can i send and receive messages through CAN

    Hi,
    how can i send and receive messages using Vector CAN CARDXL

    As mentioned in this forum post, if you have a dll, this can easily be called from LabVIEW or CVI.
    I also went to the vector website and it does look like they have LabVIEW drivers available for download.
    Peter Flores
    Applications Engineer

  • Can you send and receive Fax`s with Firefox?

    Can you send and receive Fax`s with Firefox? If so how do you do it?

    Hi invariance,
    Your printer supports eFax only, not analog faxing. To eFax, you will need to go through the registration process from the front panel of the printer. This will give you 20 faxes per month for free. If additional faxing is needed, you will need to cantact eFax and set up an account. There will be a fee for additional faxing capabilities.
    I was an HP employee.
    Reminder: Please select the "Accept as Solution" button on the post that best answers your question. Also, you may select the "Kudos" button on any helpful post to give that person a quick thanks.

  • Can my husband and I use the same e-mail address/AppleID for our 2 phones, our iMac, and our Macbook?

    Can my husband and I use the same e-mail address/AppleID for our 2 phones, our iMac, and our Macbook?
    We share an e-mail account and would like to use the same e-mail address for both our phones, as well as our computers at home. Is this possible?
    We both have itunes and apple ID's of our own right now, but since getting married, we are deleting these e-mail accounts and sharing one. How can we make this work?

    You may use the same Apple ID for iTunes and App Store purchases, but using different iCloud Apple IDs is recommended.
    If you use the same iCloud account on your iPhones it will sync all of your contacts, reminders, and notes automatically and it could be a pain. I don't know exactly how you would want to have the iCloud accounts set up on the Macs, because I don't know exactly how you use them. (I am assuming you share?). But you can do whatever you like, you can even keep the same iCloud accounts, etc but you may want to disable the syncing of certain items, because reminders for ones phone popping up on the others automatically would probably get annoying, but that is just me.

  • Can I stream and sync from the same itunes library to one AppleTV?

    Can I stream and sync from the same itunes library to one AppleTV?

    From what I can tell this is a bug.
    A very Frustrating bug. When the take 2 update launched I was streaming movies via "shared movies" from my synched computer without any issues. However after a couple of recent iTunes updates all the "shared" menus stopped appearing and I can no longer stream anything from my main computer.
    When I open up my macbook though everything streams fine, all the "shared" menus immediately appear.
    Numerous restarts, factory resets and reinstalling the 2.0 software have done nothing to help this issue.
    If anyone has any more light on the subject it'd be great to hear. Also I'm not sure which update broke it because I went about a month not using the apple tv.

  • Hello..Does anyone in this community know what the following error code indicates   0x8002006E   I was trying to burn a DVD from files in a burn folder. They were pictures from my Nikon camera. I can play videos and movies from the same dvd player.

    I was trying to burn a DVD from files in a burn folder. They were pictures from my Nikon camera. I can play videos and movies from the same dvd player.    Thanks for any help you can offer,

    Thanks for your reply:
    I did find an error log related to the error code and tried all suggestions on the list of recommendations, still no luck            
    I definitely am running OS X10.5.8 (hopefully will be updating later on this month)
    I tried several brand new discs from the same box, still no luck.
    My last option is to go out and try a different brand, guess I'll go with Verbatim this time but I think I'll poke around some more before buying 20 more new discs.

Maybe you are looking for