Can I close the connection after sending immediately on the server?

I have a C/S program. On the server side, the process as following:
1. accept (blocking)
2. //a connection is established
using a new socket to receive request data from client
3. business processing ... (maybe several seconds)
4. send response data to client
5. close socket immediately
6. listening continuely again
The server side is running on linux and writed by Java, and client is running on windows and writed by C++ Builder.
My problem is:
1. if the server is running on windows, everything is OK.
2. if the server is running on linux (that is exprcted), the client can not receive the response data from server, the client program said the connection is unavailable when he read from socket blockingly.
3. if I add some delay, e.g. 500ms, between sending response and close the connection, the client can receive response normally.
why above?
thanks for help.
Jack

Sorry, long time to go away.
package test.server;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;
public class EchoServer {
     private int port; // listened port
     private ServerSocket ssock; // the server's ip
     public EchoServer(String host, int port) {
          this.port = port;
          // Create a ServerSocket
          try {
               ssock = new ServerSocket(port);
               SocketAddress addr = new InetSocketAddress(host, port);
               ssock.bind(addr);
          } catch (Exception ex) {
               ex.printStackTrace();
          new HandleThread().start();
     public class HandleThread extends Thread {
          public int ntohl(byte[] bytes, int offset) {
               int length1 = ((((int) bytes[offset + 0]) << 24) & 0xff000000);
               int length2 = ((((int) bytes[offset + 1]) << 16) & 0x00ff0000);
               int length3 = ((((int) bytes[offset + 2]) << 8) & 0x0000ff00);
               int length4 = ((((int) bytes[offset + 3]) << 0) & 0x000000ff);
               return length1 + length2 + length3 + length4;
          public void run() {
               InputStream in = null;
               OutputStream out = null;
               try {
                    while (true) {
                         System.out.println("Start Listening...  [" + port + "]");
                         Socket clisock = ssock.accept();
                         //clisock.setSoLinger(true, 1);
                         System.out.println( "SOLinger:" + clisock.getSoLinger());
                         try {
                              System.out.println("Accepted Client Socket...  [" + clisock + "]");
                              in = clisock.getInputStream();
                              out = clisock.getOutputStream();
                              // receive four bytes length
                              byte[] lenbuff = new byte[4];
                              in.read(lenbuff, 0, 4);
                              int len = ntohl(lenbuff, 0);
                              byte[] buff = new byte[len];
                              in.read(buff, 0, len);
                              System.out.println("Received length&#65306;" + len + "  " + new String(buff));
                              Thread.sleep(1000);
                              out.write(lenbuff);
                              out.write(buff);
                              out.flush();
                              //Thread.sleep(500);
                              System.out.println("Send finished&#12290;");
                         } catch (Exception ex) {
                              ex.printStackTrace();
                         } finally {
                              if (in != null) {
                                   try {
                                        in.close();
                                   } catch (Exception ex) {
                              if (out != null) {
                                   try {
                                        out.close();
                                   } catch (Exception ex) {
                              if (clisock != null) {
                                   try {
                                        long time00 = System.currentTimeMillis();
                                        clisock.close();
                                        System.out.println( "close socket&#65306;[" + (System.currentTimeMillis() - time00) + "]");
                                   } catch (Exception ex) {
               } catch (Exception ex) {
                    ex.printStackTrace();
     public static void main(String[] args) throws Exception {
          if( args.length == 2 ) {
               new EchoServer(args[0], Integer.parseInt(args[1]));
          } else if( args.length == 2 ) {
               new EchoServer("127.0.0.1", Integer.parseInt(args[0]));
          } else {
               new EchoServer("127.0.0.1", 16000);
}In my application, the package is following:
length(4bytes) + data
I have a simple WinSocket Client, send data to this server and receive the response,the sending is OK, Server can receive all messages.But when client is ready to receive data, the winsock call return WSAECONNRESET(10054).
If I uncomment "Thread.sleep(500);", it means wait some time before close socket, the client can receive all response data.
why?

Similar Messages

  • Since installing iOS6 in my iPad2 the connection keep being bounced from the wireless all the time after a few seconds. What can I do ?

    Since installing iOS6 on my recently purchased iPad2 the connection is being bounced off the wireless all the time after a fw seconds. What can I do?

    Try #5.
    Some things to try first:
    1. Turn Off your iPad. Then turn Off (disconnect power cord for 30 seconds or longer) the wireless router & then back On. Now boot your iPad. Hopefully it will see the WiFi.
    2. Go to Settings>Wi-Fi and turn Off. Then while at Settings>Wi-Fi, turn back On and chose a Network.
    3. Change the channel on your wireless router (Auto or Channel 6 is best). Instructions at http://macintoshhowto.com/advanced/how-to-get-a-good-range-on-your-wireless-netw ork.html
    4. Go into your router security settings and change from WEP to WPA with AES.
    5.  Renew IP Address: (especially if you are droping internet connection)
        •    Launch Settings app
        •    Tap on Wi-Fi
        •    Tap on the blue arrow of the Wi-Fi network that you connect to from the list
        •    In the window that opens, tap on the Renew Lease button
    ~~~~~~~~~~~~~~~~~~~~~~~~~
    iOS 6 Wifi Problems/Fixes
    Fix For iOS 6 WiFi Problems?
    http://tabletcrunch.com/2012/09/27/fix-ios-6-wifi-problems/
    Did iOS 6 Screw Your Wi-Fi? Here’s How to Fix It
    http://gizmodo.com/5944761/does-ios-6-have-a-wi+fi-bug
    How To Fix Wi-Fi Connectivity Issue After Upgrading To iOS 6
    http://www.iphonehacks.com/2012/09/fix-wi-fi-connectivity-issue-after-upgrading- to-ios-6.html
    iOS 6 iPad 3 wi-fi "connection fix" for netgear router
    http://www.youtube.com/watch?v=XsWS4ha-dn0
    Apple's iOS 6 Wi-Fi problems
    http://www.zdnet.com/apples-ios-6-wi-fi-problems-linger-on-7000004799/
    ~~~~~~~~~~~~~~~~~~~~~~~
    How to Fix a Poor Wi-Fi Signal on Your iPad
    http://ipad.about.com/od/iPad_Troubleshooting/a/How-To-Fix-A-Poor-Wi-Fi-Signal-O n-Your-iPad.htm
    iOS Troubleshooting Wi-Fi networks and connections  http://support.apple.com/kb/TS1398
    iPad: Issues connecting to Wi-Fi networks  http://support.apple.com/kb/ts3304
    WiFi Connecting/Troubleshooting http://www.apple.com/support/ipad/wifi/
    How to Fix: My iPad Won't Connect to WiFi
    http://ipad.about.com/od/iPad_Troubleshooting/ss/How-To-Fix-My-Ipad-Wont-Connect -To-Wi-Fi.htm
    iOS: Connecting to the Internet http://support.apple.com/kb/HT1695
    iOS: Recommended settings for Wi-Fi routers and access points  http://support.apple.com/kb/HT4199
    How to Quickly Fix iPad 3 Wi-Fi Reception Problems
    http://osxdaily.com/2012/03/21/fix-new-ipad-3-wi-fi-reception-problems/
    iPad Wi-Fi Problems: Comprehensive List of Fixes
    http://appletoolbox.com/2010/04/ipad-wi-fi-problems-comprehensive-list-of-fixes/
    Fix iPad Wifi Connection and Signal Issues  http://www.youtube.com/watch?v=uwWtIG5jUxE
    Fix Slow WiFi Issue https://discussions.apple.com/thread/2398063?start=60&tstart=0
    How To Fix iPhone, iPad, iPod Touch Wi-Fi Connectivity Issue http://tinyurl.com/7nvxbmz
    Unable to Connect After iOS Update - saw this solution on another post.
    https://discussions.apple.com/thread/4010130
    Note - When troubleshooting wifi connection problems, don't hold your iPad by hand. There have been a few reports that holding the iPad by hand, seems to attenuate the wifi signal.
    ~~~~~~~~~~~~~~~
    If any of the above solutions work, please post back what solved your problem. It will help others with the same problem.
     Cheers, Tom

  • Failed to open the connection after changing the connection in CMC

    Hi
    Below are our environment details:
    BOXI 3.1 SP3
    Solaris Sparc 10
    Crystal Reports 2008 Sp3
    Weblogic 11g
    Our team is facing the problem as described below:
    We have created Crystal Reports using JDBC connection and it works fine
    in an environment(SIT).
    When we migrate these reports to the another environment(UAT) we get
    the error "Failed to open the connection"
    After migrating we indeed change the connection to Custom Database
    Login Information in CMC.
    So to troubleshoot we installed Crystal Reports in UAT environment and
    had to perform Set DataLocation after which
    the reports starting working fine.
    Now when we are migrating reports to Production we have the same issue.
    We cannot install Crystal Reports on Production this time and hence we
    are stuck.
    Please let us know if any known workaround or solution for the same.
    Thanks
    Kamal
    Edited by: Kamalaksha Shetty on Nov 15, 2011 4:18 AM

    Hi Meenal,
    I am not 100% sure I understood the workaround of having Crystal Designer on the server. Can you connect from UAT designer to production and perform the same operation?
    Check this KBA that describes this problem and a solution:
    https://service.sap.com/sap/support/notes/1445067
    Regards,
    Julian

  • Error 324 (net::ERR_EMPTY_RESPONSE): The server closed the connection without sending any data.

    Hi,
    I am using APEX version 4.2.1.00.08 with Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
    I've developed an application, that was working fine till 3 days ago...
    At the moment, I can log into the application but when I enter my ID/PW it takes me to my 1st page but then it runs for a mint or so (trying to load charts) and then generates following error message
    No data received
    Unable to load the webpage because the server sent no data.
    Here are some suggestions:
    Reload this webpage later.
    Error 324 (net::ERR_EMPTY_RESPONSE): The server closed the connection without sending any data.
    interestingly, I haven't changed anything within the application
    I've tried it with Chrome Version 27.0.1453.116 m and IE 8.0...
    with IE 8.0, it shows I/O Error in place of my graphs and get's a pop up message that displays "Error - error unknown"
    The only thing that I can recall doing differently is logging via remote desktop connection, but I've used remote desktop in the past as well and it worked.
    Please advice

    anyone...?

  • Since upgrading to Yosemite I am getting frequently "safari can't open the page (blank) because the server unexpectedly dropped the connection this sometimes occurs when the server is busy. wait and then try again"

    Since upgrading to Yosemite on my iMac I am frequently getting "safari can't open the page (blank) because the server unexpectedly dropped the connection this sometimes occurs when the server is busy. wait and then try again". This is with both a WiFi and Ethernet connection. The server is working fine from other devices using WiFi onto it such as iPhones, iPads, MacBook (which is also on Yosemite) so don't believe its an issue with the server.
    I am also noticing page load very slowly when this problem is not occurring.

    Please read this whole message before doing anything.
    This procedure is a test, not a solution. Don’t be disappointed when you find that nothing has changed after you complete it.
    Step 1
    The purpose of this step is to determine whether the problem is localized to your user account.
    Enable guest logins* and log in as Guest. Don't use the Safari-only “Guest User” login created by “Find My Mac.”
    While logged in as Guest, you won’t have access to any of your documents or settings. Applications will behave as if you were running them for the first time. Don’t be alarmed by this behavior; it’s normal. If you need any passwords or other personal data in order to complete the test, memorize, print, or write them down before you begin.
    Test while logged in as Guest. Same problem?
    After testing, log out of the guest account and, in your own account, disable it if you wish. Any files you created in the guest account will be deleted automatically when you log out of it.
    *Note: If you’ve activated “Find My Mac” or FileVault, then you can’t enable the Guest account. The “Guest User” login created by “Find My Mac” is not the same. Create a new account in which to test, and delete it, including its home folder, after testing.
    Step 2
    The purpose of this step is to determine whether the problem is caused by third-party system modifications that load automatically at startup or login, by a peripheral device, by a font conflict, or by corruption of the file system or of certain system caches.
    Please take this step regardless of the results of Step 1.
    Disconnect all wired peripherals except those needed for the test, and remove all aftermarket expansion cards, if applicable. Start up in safe mode and log in to the account with the problem. You must hold down the shift key twice: once when you turn on the computer, and again when you log in.
    Note: If FileVault is enabled in OS X 10.9 or earlier, or if a firmware password is set, or if the startup volume is a software RAID, you can’t do this. Ask for further instructions.
    Safe mode is much slower to start up and run than normal, with limited graphics performance, and some things won’t work at all, including sound output and Wi-Fi on certain models. The next normal startup may also be somewhat slow.
    The login screen appears even if you usually log in automatically. You must know your login password in order to log in. If you’ve forgotten the password, you will need to reset it before you begin.
    Test while in safe mode. Same problem?
    After testing, restart as usual (not in safe mode) and verify that you still have the problem. Post the results of Steps 1 and 2.

  • I have an icloud account which I can access via the web but when I go to systems preferences and click on the icloud it sends me to the mobileme closed site?? How do I get it to go to my icloud log in

    I have an icloud account which I can access via the web but when I go to systems preferences and click on the icloud it sends me to the mobileme closed site?? How do I get it to go to my icloud log in?

    You're saying that when you click on the  iCloud preference pane button it sends you to the defunct MMe
    rather than giving you this?
    Is your profile up to date, i.e. are your running 10.7.5?  Make sure you click on the iCloud button and not the MMe button.
    OT

  • HT201263 I see the "Connect to iTunes" screen and the device appears in iTunes. Everytime I connect to iTunes, iTunes says my device is in recovery mode and has to be recovered so I do so. The same recovery message shows in iTunes after iTunes is complete

    I see the "Connect to iTunes" screen and the device appears in iTunes. Every time I connect to iTunes, iTunes says my device is in recovery mode and has to be recovered so I do so. The same recovery message shows in iTunes after iTunes is complete. I have a iPod touch 64gb. I have no idea what OS is on it now that iTunes has tried to recover it and erased all info.

    Restore loop (being prompted to restore again after a restore successfully completes)
    Troubleshoot your USB connection. If the issue persists, out-of-date or incorrectly configured third-party security software may be causing this issue. Please follow Troubleshooting security software issues. .
    iTunes: Specific update-and-restore error messages and advanced troubleshooting

  • Cellular and wifi Ipad Mini, can i still use/connect to wifi without having the 3g sim?

    If i get a 3g and wifi Ipad Mini, can i still use/connect to wifi without having the 3g sim?  or do i HAVE to have the sim??
    i want to get the 3g and wifi Ipad...but dont want to get the 3g sim until i know i need it (as an option)

    Yes you can still connect to WiFi. You can activate cellular when you need it.

  • How do i stop a software update to the ipad after it has reached the stage of asking for itunes connection?, as i didn't sync my data to the laptop.

    How do I stop a software update of the ipad after it has reached the stage of asking for itunes connection?
    i didn't sycn my data, and itunes mentioned it will restore the ipad.
    thanks

    How do I stop a software update of the ipad after it has reached the stage of asking for itunes connection?
    i didn't sycn my data, and itunes mentioned it will restore the ipad.
    thanks

  • HT4528 How do you close programs running in the background after you update to the ios7?

    How do you close programs running in the background after you update to the ios7?  It no longer works to tap the button twice

    double tap the home button, and swiipe upp on the app screenshot

  • How can I clear a form after submitting and saving the data in the iOS Acrobat Reader App

    How can I clear a form after submitting and saving the data in the iOS Acrobat Reader App

    Darrell,
    Thanks for this response. After I posted mine, I saw that the resetForm JavaScript method is documented as being supported starting with version 10.5: http://www.adobe.com/devnet-docs/acrobatetk/tools/Mobile/js.html
    But I haven't been able to get it to work. Can you clarify if support was indeed added and if it works for you?

  • Do you have the way of fix WiFI connection after restart on unlock the macbook pro

    do you have the way of fix WiFI connection after restart on unlock the macbook pro with retina

    Toddy, see [http://news.cnet.com/8301-30685_3-20004620-264.html?tag=mncol;txt]

  • "USB device not recognized." "The connection between your device and the desktop could not be established. Please check your setup and try again." Tungsten E2, Outlook 2007

    Hi,
    I am running XP SP 2, on a Dell Vostro 1000, Palm OS Garnet v5.4.7 on a Tungsten E2. I have worked though issues relating to synchronization, Outlook 2007, Docs to Go, etc., in the past.  Thank you board members! 
    Once I worked thru all the initial problems, my Tungsten E2 was sync' ing beautifully to my laptop until a few days ago.  There have been no changes (I know of) to the configuration, but now I receive  "The connection between your device and the desktop could not be established.  Please check your setup and try again."  On the laptop I sometimes get  "USB device not recognized."  I am unclear why I get the PC message sometimes and not others.   
    I have tried the following: (not necc exactly in this order)
    Double checked Hot Sync Mgr settings: Local USB (ver. 6.0.1)
    Reset the Palm (multiple times)
    Rebooted the laptop  (multiple times before and after the Palm resets)
    Went to Support Libraries including http://kb.palm.com/SRVS/CGI-BIN/WEBCGI.EXE/,/?St=57,E=0000000001060189973,K=9550,Sxi=3,Case=Obj(3695...)
    and http://kb.palm.com/SRVS/CGI-BIN/WEBCGI.EXE?New,Kb=PalmSupportKB,ts=Palm_External2001,Case=obj(1409) 
    Followed the steps in "Start Here" found at  http://forums.palm.com/palm/board/message?board.id=windows_hotsync&thread.id=26057 
    Moved Backup directory as per a post on this forum
    Looked for a deleted a file called "Graffiti_ShortCuts_____________" per a post on this forum
    Followed the steps in HotSync troubleshooter guide you can run through located on
    http://kb.palm.com
    Went into Device Manager - found it shows no yellow ! 's
    Followed Device Mgr Troubleshooter - went all the way thru with no solution 
    Tried all four USB ports - the PC's bell-like tone does not sound when I disconnect or reconnect the Plam's cradle like it does when I conn/disconnect other USB devices -I think that is a clue.    ...? 
    Cleaned the Palm's contacts (and cradle's contacts with a old, dry toothbrush)
    Read all the posts under "USB device not recognized." 
    OK, I'm at a loss, can anyone help me?  Many thanks in advance! 
    ~Bob
    Post relates to: Tungsten E2

    Hello!
    Using a cradle with the Tungsten E2?  Tried bypassing the cradle and just use the hotsync cable?  Tried a different computer yet?  Somehow, the PC is having problems getting a signal from the device.  I assume you have the laptop charger plugged into the laptop during this?  Not going through a docking station or port-replicator.
    One crazy thing you can try is unplug the charger from your laptop, remove the battery from the laptop and leave it out for like 10mins and put it back in and reboot the laptop.  This should not cause side effects but still contact your OEM to make sure that nothing else is needed after leaving the battery out for extended period of time.  Keep me posted.
    Post relates to: Treo 650 (Unlocked GSM)

  • Problem: Hotsync error message "The connection between your device and the desktop could not be establisthed."

    When I Hotsync Bluetooth connection is successful, then in step 2, "Connecting with the desktop" Hotsync errors out with message "The connection between your device and the desktop could not be establisthed.  Please check your setup and try again."
    Bluetooth configuration inticates Bluetooth serial port COM Port is set to COM3
    Hotsync setup: when I click "Local" tab I get error message "The selected port, COM5, is not available at this time.  HotSync Manager will open the port when it becomes available."
    Hotsync setup > "Local" tab > Serial Port dropdown shows only COM4.  I cannot change it to anything else.
    Note: I can send files to PC using Bluetooth just fine; error only occurs when I Hotsync using Bluetooth connection.
    Tried rebooting both laptop and Palm TX.  Still can't Hotsync.
    Operating system: Windows XP Pro
    Post relates to: Palm TX

    You are not the only one having this problem. I have REPEATEDLY tried to bluetooth sync with my new toshiba windows 7
    Palm 6.2.2 to no avail. I have tried every bluetooth device they suggest and every "fix" or "solution" that has been offered here and in on line chat with a Palm tech. No dice! I even took my computer and all components to a tech. He worked on it for 5 hours. Every once in a while for no apparent reason it will magically sync, but never consistently. Using 32bit on my husband's computer with Vista, and the docking cradle still works so I have my data. A few others have apparently had success with this problem but I think it is an accident that it works for them when it does. Otherwise it would work for everyone. We have read everything we can find and spent literally hours and hours and hours.
    I am now in the process of trying to import/export to Outlook and plan to upgrade to another device like iPhone or blackberry that will sync data with Outlook. My Palm TX also has not been able to successfully sync with that although, as I said earlier, it syncs with Palm Desktop. Good luck with your's.

  • Forgot the passcode to my ipad. When I went to restore it, it asked me if I wanted to update the software so I said yes. It then went into recovery mode, I'm guessing, with the connect to iTunes showing on the screen. Now iTunes will not recognize it??

    Forgot the passcode to my ipad. When I went to restore it, it asked me if I wanted to update the software so I said yes. It then went into recovery mode, I'm guessing, with the connect to iTunes showing on the screen. Now iTunes will not recognize it so I have no idea how to get it back! Help!!

    Then you will need to try restoring it once more:
    Placing your device into recovery (DFU) mode:
    Follow these steps to place your iOS device into recovery mode. If your iOS device is already in recovery mode, you can proceed immediately to step 6.
       1. Disconnect the USB cable from the iPhone, iPad, or iPod touch, but leave the
           other end of the cable connected to your computer's USB port.
       2. Turn off the device: Press and hold the Sleep/Wake button for a few seconds
           until the red slider appears, then slide the slider. Wait for the device to turn off.
                  * If you cannot turn off the device using the slider, press and hold the
                    Sleep/Wake and Home buttons at the same time. When the device turns off,
                    release the Sleep/Wake and Home buttons.
      3. While pressing and holding the Home button, reconnect the USB cable to the
           device. The device should turn on. Note: If you see the battery charge warning,
           let the device charge for at least ten minutes to ensure that the battery has some
           charge, and then start with step 2 again.
      4. Continue holding the Home button until you see the "Connect to iTunes" screen.
           When this screen appears you can release the Home button:
      5. If necessary, open iTunes. You should see the following "recovery mode" alert:
      6. Use iTunes to restore the device.
    If you don't see the "Connect to iTunes" screen, try these steps again. If you see the "Connect to iTunes" screen but the device does not appear in iTunes, see this article and its related links.
    Additional Information:
    If you have a problem getting into recovery mode then try: RecBoot: Easy Way to Put iPhone into Recovery Mode.
    Note: When using recovery mode, you can only restore the device. All user content on the device will be erased, but if you had previously synced with iTunes on this computer, you can restore from a previous backup. See this article for more information.

Maybe you are looking for

  • Camera Raw 6.7 fails to update, even after manual install?

    Whenever I run the check for updates in Photoshop (CS5), it tells me I need to update Camera Raw to 6.7.  However, when I try, I get this message:   Photoshop Camera Raw 6.7 Update   There was an error downloading this update. Please quit and try aga

  • According to PO number and Line item data should come once but its repeatin

    I am calculating IR Quantity and IR value...... for a PO  if there are four same  line items i wanted them once but they are displaying for each and every line item If my po is 2003000151 and line item 0010 if both are same then i wanted ir quantity

  • Any "best practices" for managing a 1.3TB iPhoto library?

    Does anyone have any "best practices" or suggestions for managing and dealing with a large iPhoto library?  I currently have a 1.3 TB library.  This is made up of anything shot in the past 8 years culminating with the past 2 years being 5D Mark II im

  • Displaying numbers not names in messages

    My iPhone 5 is displaying numbers when I get messages not names Any ideas? TIA

  • PI Mapping problem - Repeating target nodes

    Hello PI buddies! My PI mapping problem is as follows: I have a source IDoc which I wish to map to a JDBC Message Type. In the Idoc I have 2 repeating sections that I wish to combine to create a new node in the target for each combination of the 2 re