Socket reconnection issue

Hi,
our aim of using the sockets is to send the HL7-message to HL7-engine.
while reconnecting to the engine(server) i am following the steps
1. close the outputstream of the socket
( socket.getOutputStream().close() )
2. close the socket
( socket.close() )
3. wait for 2 minutes and
4. create the socket and connect to engine
imedxORUChannel = new Socket();
imedxORUChannel.connect(new InetSocketAddress(getREMOTEHOST(), getREMOTEPORT()));
5. sometimes client socket is getting connected to server , sometimes not.
i want the socket to connect to remote host with in small span of time.
can any one provide the solution for this.
thanks in advance .

while reconnecting to the engine(server) i am following the steps
1. close the outputstream of the socket
( socket.getOutputStream().close() )
2. close the socket
( socket.close() )Unnecessary if you've closed the output stream.
3. wait for 2 minutes and Why?
5. sometimes client socket is getting connected to server , sometimes not.What exception is thrown when it fails? Show the complete exception text.
i want the socket to connect to remote host with in small span of time.It should connect within seconds, or fail after not more than about 75 seconds. You can reduce that timeout by calling the connect() method that takes a timeout parameter.

Similar Messages

  • Cellular reconnectivity issues with 3rd Gen iPad 3G/4G/LTE

      I've read a few other threads regarding a reconnection issue with the new (3rd Gen) iPad. I'm creating a discussion so people can put there thoughts here regarding the issues they are having with reconnection of cellular data connections.
      I have AT&T 64B iPad Gen 3 with 4G/LTE. Black. Works just fine on wifi and my LTE screams at home and work. Faster than my cable at home. I have noticed something behavior regarding data connection when it's lost (like in a tunnel). I ride DC Metro to work and go through a few tunnels. Of course, my data connection drops in the tunnels. When I come back out the indicator on the iPad indicates 5 bars signal and LTE again. Problem is the data connection isn't there, no matter what app I try. I even get a popup window say my cellular data plan has not been activated (huh?). This isn't true since I am on, and have been using a plan. It does this whether it's 4G or LTE reconnection. Not sure about 3G because I haven't seen 3G icon popup on this iPad yet.
    I'm thinking this may be an authentication issue? Else, why would it popup that warning? Anyway, all I do is is go into settings turn cellular data off and back on again and everything is fine.
      I'm guessing that there could be a software fix for this in the future as there are quite a bunch of people having this problem with reconnection to cellular.
    Please post your issues here in this discussion if you have this problem. Maybe we can figure something out.

    I have the same iPad (3rd gen, 4G ATT, 64GB, Black).  When it arrived last Friday, everything seemed to work fine, except the cellular data connection.  It would constantly drop, and I had to toggle cellular data off and back on to get it back.  Also, I was getting really slow speeds (on cellular data only - wifi works fine).  I tried some simple fixes (restarting, resetting the network settings, restoring), but I kept having the problem.  I finally made an appointment at the Genius Bar, and they immediately gave me a new iPad, saying "it could be a bad antenna."  Here is the bad news.  Even with the replacement, the connection seems to drop less often, but it still drops. The part that concerns me most is that the data speeds on my iPad are considerably slower than on my iPhone 4S when I test them in the exact same spot (I use the Speed Test app).  So on my iphone, I get speeds around 3 Mbps, and on the iPad, I get speeds of less than 1Mbps.  I can't see any logical reason that the 3rd gen iPad would not get at least as good or better data speeds as an iPhone 4S.  The fact that I have now had two 3rd gen iPads with cellular data problems concerns me.  However, it is very hard to tell if this is a software, hardware, or network issue.  The fact that my iPhone is running the same update of iOS (5.1), and has no problems would seem to eliminate the software and network as causes, but I can't really be sure.  I am going to watch the posts in the support communities for another day or two and then head back to the Genius Bar.  Overall I love the new iPad, but this has been a real downer. 

  • Socket security issues

    Hello,
    I am developing an messaging application, similar to MSN or AIM. so only text messages are passed over a socket.
    Does anybody know of any socket security issues there are when opening a socket on a particular port in java?
    If so then does anybody know if there is any documentation out there that i can look at?
    Thanks

    psamatt wrote:
    Hello,
    I am developing an messaging application, similar to MSN or AIM. so only text messages are passed over a socket.
    Does anybody know of any socket security issues there are when opening a socket on a particular port in java?
    If so then does anybody know if there is any documentation out there that i can look at?
    Simple sockets are wide open - there is no security. Secure sockets are implemented as a layer on top of simple sockets using JSSE - http://java.sun.com/j2se/1.4.2/docs/guide/security/jsse/JSSERefGuide.html .

  • Reconnect issues

    Hi,
    I'm having an odd issue with Color that's ruining our project. We did an edit in FCP 6.0.4 with R3D footage converted to ProRes and did an offline edit. After the edits were made, we offlined the timeline clips, and batch captured the footage as REDCODE, and moved it all over to Color. Here's where things went wrong. I copied the Color project file, all related media, and the media-managed FCP project file to an external drive and sent it to the post house for online. When they got it, all the colors looked crunched. All the settings were the same, REC709, ISO320, grades were the same.
    They called and said that by changing the ISO of the REDCODE clips, it comes out ok for them, so I'm guessing there's a discrepancy with our 1.0.3 version compared to whatever they have. That's problem 1, figuring out what caused the color crunch.
    The second problem came when I tried to load the Color project on our end again. All the media was disconnected, and using the Reconnect utility under File, or clicking "reconnect" under the right-click menu didn't do anything, despite selecting the exact clip. I updated to 1.0.4 from 1.0.3 after learning about the reconnect and ISO issues of 1.0.3, and Color only reconnected half of my clips. Does anyone know what the reconnect issue is?
    Thanks in advance.

    Right click on the COLOR timeline and see if the reconnect media dialog helps.
    jPo

  • Reconnecting issues

    after i did a operating system update, a few months ago, i lost connection with my printer. now i am trying to reconnect and the computer cant even find the printer. my computer said to make sure my bluetooth was working on the computer and i cant even find that.  I also have a hp computer (dont know the model.)

    Hi @peanut87,
    Welcome to the HP Forums!
    I understand that you are having reconnecting issues with your HP Photosmart c4795 on Windows 8.1. I am happy to look into this connection issue for you!
    How is your printer connected? Wireless or USB?
    In the meantime, please try the HP Print and Scan Doctor, and let me know what happens!
    Hope to hear from you soon, and have a nice day!  
    RnRMusicMan
    I work on behalf of HP
    Please click “Accept as Solution ” if you feel my post solved your issue, it will help others find the solution.
    Click the “Kudos Thumbs Up" to say “Thanks” for helping!

  • RFC Adapter reconnect issue

    hi
    We have a problem with RFC connection with SAP System on production.
    I consuder to change  <b>initialRfcClientConnectCheck</b> to <b>false</b>.
    But in this case RFC adapter will check connection each time. It is not good for performace.
    What doy think is it good practice to have <b>initialRfcClientConnectCheck=false</b> on production system? I don't see another way How to force XI reconnect after shutdown of SAP System.

    Hi,
    Apart from setting this option there is no other way out.
    We have made this change in our production and we have faced no issue in terms of perfromance after setting the parameter!
    Regards
    Bhavesh

  • Reconnecting Issues with Batch List

    Hello,
    I am working with a client who created a ton of sub-clips and sent me a batch list of them. He is using FCP 7.0.3 and I am using 6.0.6. When imported, all of the subclips show up with the same name in the browser window (not sure if this is standard as I haven't used batch lists before).
    I am having two issues:
    - Since there are a ton of subclips, I am obviously hoping to reconnect all of them at once. However, when I go to reconnect, even though I highlight all the clips in the browser window and have checked off the "reconnect all files in similar path" box- it will only reconnect one sublicip at a time.
    - For some reason when the sublips do reconnect (one at a time) they are converted to 4:3 from anamorphic- so I have to go into Item Properties and manually check off the anamorphic box to make them normal.
    Obviously I can continue with the project, but it will take me a long time to reconnect each sublicip individually and then re-anamorphic (sorry for the made up word) each one manually. It's going to take a long time.
    Any suggestions?
    Thank you.

    Michael,
    Thanks again. I understand now what you are saying. When I reconnect, the dialogue box lists the files as coming from an "Unspecified Path." However, It's finding the files just fine- and it says it can reconnect the clips. However, when it does, it only reconnects one subclip at a time, even though I have highlighted them all. That's the issue. Since all the sublicips I am trying to reconnect have the same name in the browser (they are all named the same as the original clip), FCP will only connect one at a time (apparently it seems to think that the files are all one because they have the same names).
    Same thing with selecting multiple clips and then going to Item Properties and clicking on anamorphic- FCP thinks all the clips are really one clip, so it only reconnects one at a time.
    Hopefully I am being clear with the problem.
    Thanks!

  • CSS 11501 - Network reconnection issue

    Using a CSS 11501 switch to configure both Load balancing and server hot standby between two servers (of same config). Clients are connecting to the server using tcp/ip sessions.
    The configuration used is shown below:
    =========================================
    configure
    ip route 0.0.0.0 0.0.0.0 10.167.50.1 1
    !************************* INTERFACE
    interface e2
    bridge vlan 9
    interface e3
    bridge vlan 9
    !************************** CIRCUIT
    circuit VLAN1
    ip address 10.167.50.108 255.255.254.0
    circuit VLAN9
    ip address 10.167.70.1 255.255.254.0
    !************************** SERVICE
    service abc_service1
    ip address 10.167.70.2
    protocol tcp
    port 6300
    keepalive type tcp
    active
    service abc_service2
    ip address 10.167.70.3
    protocol tcp
    port 6300
    keepalive type tcp
    active
    !*************************** OWNER
    owner xxxxx
    content abc_crule
    vip address 10.167.50.109
    add service abc_service1
    add service abc_service2
    protocol tcp
    port 6300
    balance aca
    active
    ===============================
    We conducted three tests to verify the hot standby while client sending the data to server app thro tcp/ip.
    1) Brought down the service on one server 2) Restarted the OS (Windows 2003) on one server 3) Removed a network cable of one of the server connecting to CSS.
    client app lost the conn to the service/server, but when it tried reconnecting to the alternate server, it was successful.
    CSS status reflected the actual status of the service/server.
    But in third test (removing network conn) the service state changed from "Alive" to "Down" and client app lost conn to the server. Client app tried reconnecting and it was successful connecting to the alternate server.
    But when we connected the network cable back, the CSS state was continue to be in "Down". Also,the network connection between CSS and server was not available after reconnection. Also, the status of alternate server changed to "Down", but still client app was successfully transmitting to the alternate server. Stopping the client app and tried reconnecting,
    the connection was not going thro.
    The connection could be established between CSS and server boxes only after restarting the OS(running windows 2003).
    Issues:
    1. Service status in CSS continue to be down even after reconnecting the cable with the service running.
    2. CSS status of the first service also went down after reconnecting the other server.
    3. Client app could not reconnect to any of the servers.
    Are we missing any configuration parameter in CSS which will address the above?
    regards
    Param

    Param,
    what software version for the CSS ?
    Did you see an ARP entry on the server for the CSS ?
    Did you see an ARP entry on the CSS for the server ?
    is the server directly connected to the CSS or is there an L2 switch inbetween ?
    Could you configure 'bridge spanning-tree disabled' on the CSS and see if this improves the situation.
    Regards,
    Gilles.

  • WRT350N: Unable to connect or ping wireless client on LAN, and reconnect issue

    I own a WRT350N (V2.00.17), it's a great piece of hardware. But I can't seem to connect to a client connected over the wifi. In the terms of "ping":
    * ping wifi-client from wired-client - Not OK
    * ping wifi-client from other wifi-client - Not OK
    * ping wired-client from wif-client - OK
    * ping wired-client from other wired-client - Not OK
    Another example:
    I have a server (192.168.1.100) on wifi serving Windows shares, this server is on wifi. All the clients on the LAN is also on wifi, however trying to connect to the server with \\192.168.1.100 returns a timeout message. I have created a port forward rule that forwards all traffic on 137-139 to 192.168.1.100. If my public IP is 123.123.123.123 I then can connect to my Windows shares on the server via \\123.123.123.123
    Another issue is that if a wifi-client is inactive network-wise for some time (perhaps as low as 5 minutes) the wifi-client needs to reconnect to the router, could this be "fixed" on the router-side?
    Regards
    //archangel
    Solved!
    Go to Solution.

    It seems that the "AP Isolation" option had a hickup. Enabled it, saved, disabled it, saved. Now it's working.

  • OC4J bind socket address issue

    Hi i am using DB(9.2.0.6.0) and APPS(11.5.10.2).  Now i have cloned a new instance and it runs on port 8050. Now i want to install and configure OC4J with it. I have done the OC4J Installation Successfully. Here i used the OC4J Version 9.0.3.I have changed the http-web-site.xml port number to 8890 and rmi.xml port to 23793 as per the document i got.To create the starting script, file name called “.start_oc4j” I issued cd $OC4J_TOP/j2ee/home/ then
    java -jar oc4j.jar and
    it throws the error
    [applpdev@oraapps ~]$ cd $OC4J_TOP
    [applpdev@oraapps home]$ pwd
    /pdev/p01/oracle/pixappl/pwr/11.5.0/oc4j/
    [applpdev@oraapps oc4j]$ cd j2ee/home/
    [applpdev@oraapps home]$ java -jar oc4j.jar
    Error starting JMS-Server: Unable to bind socket: Address already in use
    Error starting ORMI-Server.  Unable to bind socket: Address already in use
    [applpdev@oraapps home]$

    Hi Hussein,
         Now i am facing a new issue. I am using oc4j 9.0.3 version. When i started the oc4j i am getting the following error.
    [applpdev@oraapps home]$ java -jar oc4j.jar
    Auto-deploying ejb (No previous deployment found)... Exception in thread "Orion Launcher" java.lang.NoClassDefFoundError: sun/jdbc/rowset/CachedRowSet
            at java.lang.Class.getDeclaredMethods0(Native Method)
            at java.lang.Class.privateGetDeclaredMethods(Class.java:2427)
            at java.lang.Class.privateGetPublicMethods(Class.java:2547)
            at java.lang.Class.getMethods(Class.java:1410)
            at
    com.evermind.server.ejb.compilation.ClassCompilation.compileMethods(ClassCompilation.java:84)
            at com.evermind.server.ejb.compilation.StatelessSessionBeanCompilation.compile(StatelessSessionBeanCompilation.java:40)
            at com.evermind.server.ejb.compilation.Compilation.compile(Compilation.java:288)
            at com.evermind.server.ejb.EJBContainer.postInit(EJBContainer.java:551)
            at com.evermind.server.Application.postInit(Application.java:431)
            at com.evermind.server.Application.setConfig(Application.java:136)
            at com.evermind.server.ApplicationServer.addApplication(ApplicationServer.java:1635)
            at com.evermind.server.ApplicationServer.initializeApplications(ApplicationServer.java:1585)
            at com.evermind.server.ApplicationServer.setConfig(ApplicationServer.java:1240)
            at com.evermind.server.ApplicationServerLauncher.run(ApplicationServerLauncher.java:93)
            at java.lang.Thread.run(Thread.java:662)
    Caused by: java.lang.ClassNotFoundException: sun.jdbc.rowset.CachedRowSet
            at com.evermind.naming.ContextClassLoader.findClass(ContextClassLoader.java:456)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
            at com.evermind.naming.ContextClassLoader.loadClass(ContextClassLoader.java:135)
            at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
            ... 15 more
    So i uninstalled jdk1.6.0 and installed jdk1.4.2 and i started the OC4J. The default web page is displayed. Now i moved a .ear file to the directory APPL_TOP/pwr/11.5.0/oc4j/j2ee/home/applications added the entries in the server.xml,application.xml,http-web-site.xml and the directory is created for the respective .ear file. Under the path APPL_TOP/pwr/11.5.0/oc4j/j2ee/home/applications there are two default directories called dms0 and dms and they are accessible through the browser but my directory created by the .ear file is not accessible through the browser and it throws the error Can't find the directory. I checked the log and the content is
    12/5/13 6:06 PM iLogin: JspServlet: unable to dispatch to requested page: Exception:oracle.jsp.provider.JspCompileException: <H3>Errors compiling:/pdev/p01/oracle/pixappl/pwr/11.5.0/oc4j/j2ee/home/application-deployments/iLogin/iLogin/persistence/_pages//_iLogin.java</H3><pre>error: Invalid class file format in /usr/java/j2sdk1.4.2_19/jre/lib/rt.jar(java/io/PrintWriter.class).  The major.minor version '48.0' is too recent for this tool to understand.
    /pdev/p01/oracle/pixappl/pwr/11.5.0/oc4j/j2ee/home/application-deployments/iLogin/iLogin/persistence/_pages/_iLogin.java:11: Class java.io.PrintWriter not found in import.
    import java.io.PrintWriter;
           ^
    error: Invalid class file format in /usr/java/j2sdk1.4.2_19/jre/lib/rt.jar(java/io/IOException.class).  The major.minor version '48.0' is too recent for this tool to understand.
    /pdev/p01/oracle/pixappl/pwr/11.5.0/oc4j/j2ee/home/application-deployments/iLogin/iLogin/persistence/_pages/_iLogin.java:12: Class java.io.IOException not found in import.
    import java.io.IOException;
           ^
    error: Invalid class file format in /usr/java/j2sdk1.4.2_19/jre/lib/rt.jar(java/sql/Connection.class).  The major.minor version '48.0' is too recent for this tool to understand.
    /pdev/p01/oracle/pixappl/pwr/11.5.0/oc4j/j2ee/home/application-deployments/iLogin/iLogin/persistence/_pages/_iLogin.java:14: Class java.sql.Connection not found in import.
    import java.sql.Connection;
    </pre>
    12/5/13 6:06 PM iLogin: Recursive error in error-page calling for /iMODError.jsp
    javax.servlet.ServletException: Recursive error in error-page calling for /iMODError.jsp (status 500)
      at com.evermind[Oracle9iAS (9.0.3.0.0) Containers for J2EE].server.http.EvermindHttpServletResponse.sendError(EvermindHttpServletResponse.java:1204)
      at oracle.jsp.runtimev2.JspReportUtil.sendError(JspReportUtil.java:96)
      at oracle.jsp.runtimev2.JspReportUtil.reportException(JspReportUtil.java:125)
      at oracle.jsp.runtimev2.JspPageTable.compileAndServe(JspPageTable.java:573)
      at oracle.jsp.runtimev2.JspPageTable.service(JspPageTable.java:272)
      at oracle.jsp.runtimev2.JspServlet.internalService(JspServlet.java:465)
      at oracle.jsp.runtimev2.JspServlet.service(JspServlet.java:379)
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
      at com.evermind[Oracle9iAS (9.0.3.0.0) Containers for J2EE].server.http.ServletRequestDispatcher.invoke(ServletRequestDispatcher.java:721)
      at com.evermind[Oracle9iAS (9.0.3.0.0) Containers for J2EE].server.http.ServletRequestDispatcher.forwardInternal(ServletRequestDispatcher.java:306)
      at com.evermind[Oracle9iAS (9.0.3.0.0) Containers for J2EE].server.http.ServletRequestDispatcher.forward(ServletRequestDispatcher.java:209)
      at com.evermind[Oracle9iAS (9.0.3.0.0) Containers for J2EE].server.http.EvermindHttpServletResponse.sendError(EvermindHttpServletResponse.java:1244)  and the same errors are repeated

  • Reconnect issues w/FCP 6 with "phantom missing clips"

    Ok folks it's kinda hard to describe in a concise way what's going on so please bear with me.
    We are working with FCP6 on multiple machines.
    We have one master project file that Edit 1 houses.
    We work on the other machines on a copy of that master project file and bring in the work sequences into the Edit 1 master project as they are completed.
    We do this a lot and move sequences around.
    Ever now and then we have serious reconnection to media issues on the main machine where when I go to reconnect a sequence to the media files it will bring up a ton of "blank" or "phantom" clips in the missing files box in the reconnect window. Basically instead of a list of clip names that FCP wants me to reconnect it will list a batch of clips that are blank with no txt and therefore we have no way of connecting that media.
    Has anyone experienced this issue before and how have you worked around this?
    any help very much appreciated and if you need more info to understand what the **** I'm talking about then please let me know!
    J

    I've never been able to truly get that to happen properly.
    Over the break I will give that one more shot.
    On the two main systems we work with we do have the same size and config of drives etc so it can be achieved. I'll take a look at that option over the break and see if I make make it happen.
    I do take the project home at times and media manage the footage into a much smaller drive to work on sections of the project so in that case there's no way around it. Although I guess if I keep the naming and folder structure the same it's possible. I'll give that a try too.
    thx.

  • Wireless Reconnection Issue (broadcom-wl)

    I installed the broadcom-wl driver from the AUR to use the wireless chip in a Dell Inspiron 1525, and I have a strange issue now. When I boot the machine, I can connect to one of the building's two WEP-encrypted networks (yes, I know they should change to a different encryption standard). If I disconnect or need to switch to the other AP, dhcpcd seems to fail. I'm using wicd to connect to the network. It throws "could not get an IP address" when I try to reconnect. The only solution is to reboot the machine—I even tried unloading all the associated network modules (lib80211_crypt_tkip and wl), restarting wicd, and prowling for any remaining instances of dhcpcd. What can I do to fix this?
    Here is some information that might help:
    $ lspci -vnn | grep 'Broadcom'
    0b:00.0 Network controller [0280]: Broadcom Corporation BCM4312 802.11b/g [14e4:4315] (rev 01)
    wicd.log during a reconnection attempt:
    2010/11/18 11:43:17 :: Attempting to authenticate...
    2010/11/18 11:43:17 :: ['wpa_supplicant', '-B', '-i', 'eth0', '-c', '/var/lib/wicd/configurations/0024c8835230', '-D', 'wext']
    2010/11/18 11:43:17 :: ['iwconfig', 'eth0', 'essid', '<essid>']
    2010/11/18 11:43:17 :: iwconfig eth0 channel 8
    2010/11/18 11:43:17 :: iwconfig eth0 ap 00:24:C8:83:52:30
    2010/11/18 11:43:17 :: WPA_CLI RESULT IS DISCONNECTED
    2010/11/18 11:43:18 :: WPA_CLI RESULT IS COMPLETED
    2010/11/18 11:43:18 :: Running DHCP with hostname thopkins
    2010/11/18 11:43:18 :: /sbin/dhcpcd eth0
    2010/11/18 11:43:18 :: dhcpcd[4732]: version 5.2.8 starting
    2010/11/18 11:43:18 ::
    2010/11/18 11:43:18 :: dhcpcd[4732]: eth0: broadcasting for a lease
    2010/11/18 11:43:18 ::
    2010/11/18 11:43:41 :: found backend in configuration external
    2010/11/18 11:43:48 :: dhcpcd[4732]: timed out
    errors.log from around the same time:
    Nov 18 11:42:44 localhost dhcpcd[4591]: dhcpcd not running
    Nov 18 11:42:44 localhost dhcpcd[4597]: dhcpcd not running
    Nov 18 11:42:44 localhost dhcpcd[4604]: dhcpcd not running
    Nov 18 11:43:10 localhost dhcpcd[4697]: dhcpcd not running
    Nov 18 11:43:15 localhost dhcpcd[4706]: dhcpcd not running
    Nov 18 11:43:15 localhost dhcpcd[4712]: dhcpcd not running
    Nov 18 11:43:15 localhost dhcpcd[4719]: dhcpcd not running
    Nov 18 11:43:48 localhost dhcpcd[4732]: timed out
    Nov 18 11:43:48 localhost dhcpcd[4743]: dhcpcd not running
    Nov 18 11:43:48 localhost dhcpcd[4749]: dhcpcd not running
    Nov 18 11:45:24 localhost dhcpcd[4615]: dhcpcd not running
    Nov 18 11:45:24 localhost dhcpcd[4621]: dhcpcd not running
    Nov 18 11:45:24 localhost dhcpcd[4628]: dhcpcd not running
    Let me know if you want to see anything else to diagnose this.
    Last edited by Snowknight (2010-11-18 18:47:28)

    Improper forum aside, I do not have this issue with networkmanager. I'll poke around a bit later and see if I should report a bug somewhere. I would mark this as solved, but it's not really solved as much as allayed.
    Last edited by Snowknight (2010-11-20 01:47:11)

  • Socket Reconnect

    Hi, I've written a very basic chat program in my efforts to learn more about socket programming in Java, I'm having a slight bit of trouble though.
    The problem is that when the client disconnects, it cannot reconnect again unless both the server and client are restarted. I'm looking to fix this so that the client can disconnect and reconnect as many times as they like because later I'll be adding the abuility for many clients to connect and disconnect.
    The code is abit large to be posted here but it's availiable on sourceforge at
    http://sourceforge.net/projects/roxcom/
    if you'd like to take a look.
    Thanks for any help in advance.
    Ross

    Ok, this method seems to work fine however, if teh client disconnects from the server, the server needs to try and send text before it will find the error, close and start waiting for the next client. The only way I can think to get round this is to send some sort of SYN<->ACK strings. Is this right?
    out.println(txString);
    if (out.checkError())     // Changed for flush()
        if (!isHost())
          disconnect();
        else
            try{
                clientSocket.close();
                hostSocket.close();          
            }catch(IOException e) {
                sendDebugString("Error Closing Host");
            status=CREATINGHOST;
            return false;
    else
        return true;
    }

  • Client Socket Reconnect Question

    I have a client that is connecting a socket to a piece of hardware (Computer Controlled Telescope). No guarantee that the hardware is powered up when the app starts and the hardware might power down and back up at any time.
    The app�s main thread creates a socket to the device. A child thread gets the socket�s OutputStream to send commands to the device. Another child thread gets the socket�s InputStream to receive status from the device.
    Problem: How do I recognize that the device has died? What do I have to do to the socket to reconnect it?

    I only pass the InputStream and OutputStream to my child threads. The Socket stays snug and secure in my main thread.
    Also, I don't want to hide the fact the socket has gone away, just the opposite , I want to know that the socket has died (Socket.isConnected(), I guess), recreate it to the same IP address, and re-distribute the In/Out Streams to the child threads.
    I guess my questions are: 1) How can I tell that the thread has died? and 2) How do I recreate the socket?

  • Server socket programming issue

    Hi there and thanks for visiting my post,
    I'm writing a instant message application. I've written a multi-threaded server that constant listens for socket connections on port 4001. When a connection is received by the server, it adds the thread (client) connection to an array (of fixed size, I allow a max of 100 connections or so) and starts the thread. Here's the code:
    import java.io.*;
    import java.util.*;
    import java.net.*;
    * @author Stephen
    public class Main {
        static ServerSocket         sock = null;
        static pmClientHandler      conn;
        static Socket               client = null;  
        static int                  port = 4001;
        static int                  MAX_CONNECTIONS = 100;
        static pmClientHandler      t[] = new pmClientHandler[MAX_CONNECTIONS]; // array that holds threads holds a max of 100 now
        /** Creates a new instance of Main */
        public Main() { }
         * Instantiate server listener
         * @param args the command line arguments
        public static void main(String[] args) {
            // TODO code application logic here
            try {
                sock = new ServerSocket(port);  // listen on port
            } catch (IOException e) {
                System.out.println("Cannot create server on port "+port+".");
                System.exit(1);
            System.out.println("Pita messenger server ready on port  "+port+". Listening for connections...\n\n");
            while (true) {    // infinite loop to listingen for many connections
                try {
                client = sock.accept();  // accept connection
                for (int i =0; i < MAX_CONNECTIONS; i++) {
                    if (t[i] == null) {
                       (t[i] = new pmClientHandler(client,t,MAX_CONNECTIONS)).start();
                       break;      
                } catch (IOException e) {  // ERROR ACCEPTING CONNECTION 
            } // end infini. loop listening for remote socket connections
    }Again, each instance thread object of pmClientHandler constantly listens for incoming messages from the client application. Here's the code for that class.
    import java.util.*;
    import java.net.*;
    import java.io.*;
    public class pmClientHandler extends Thread {
    public String       username = "";
    private boolean     userValidated = false;
    public boolean      userAway = false;
    public boolean      userInvisible = false;
    public boolean      userBusy = false;
    private ArrayList   currentBuddyList;
    public Socket      connection;
    public pmClientHandler t[];
    private Scanner     reciever;
    public PrintStream  sender = null;
    private int         MAX_CONNECTIONS;
    private boolean     isConnected = false;
        /** Creates a new instance of pmClientHandler */
        public pmClientHandler(Socket s, pmClientHandler[] newThread, int maxc) {
            connection = s; // hand over socket
            MAX_CONNECTIONS = maxc;
            t = newThread; // hand over thread. We now have new populate array of clients in t[]
            isConnected = true;  // user connected
            try {  // create IO streams for this particular client
                reciever = new Scanner(connection.getInputStream()); 
                sender = new PrintStream(connection.getOutputStream(), true);  //auto flush true
            } catch (IOException e) { close(); }
         * Required method by threads. Method is called when thread is executed.
         public void run() {
          String clientMessage;
          pmServerMessenger resource = new pmServerMessenger();
          while(isConnected) { 
            // Determine username and password request
            clientMessage = reciever.nextLine().trim();
            ///////////////////////  HANDLE PROTOCOL / MESSAGES  /////////////////////////////////
            // So we know user has established a connection to the server but has not yet logged in yet.
            if (clientMessage.toUpperCase().startsWith("ECHO")) { sender.println("ECHO BACK, HELLO CLIENT"); }
            if (clientMessage.startsWith("LOGIN")) {  // client wishes to log in
                clientMessage = clientMessage.substring(5).trim();
                if (clientMessage.indexOf(" ") != -1) {
                    String suppliedUsername, suppliedPassword;
                    suppliedUsername = clientMessage.substring(0, clientMessage.indexOf(" ")).trim();
                    suppliedPassword = clientMessage.substring(clientMessage.indexOf(" ")).trim();
                    // Valid user
                    if (resource.validateUser(suppliedUsername, suppliedPassword)) {    
                        sender.println("ACDFG324323DSSDGTRR54745345DFGDFSE3423423DHDFHER4565DFGDFGERT");  // send key to client
                        userValidated = true;   // set flag to allow user to access server resources.
                        this.username = suppliedUsername;
                    } else {
                        sender.println("INVALIDLOGIN");
                } else {
                    sender.println("INVALIDLOGIN");
                    this.close();
            } // end user login routine //////////////////////////////////////////////
            if (clientMessage.toUpperCase().startsWith("LOADBUDDYLIST")) {
                if (isConnected && userValidated) {
                    ArrayList thisUsersBuddyList = resource.getBuddyList(this.username);
                    for (int i = 0; i < thisUsersBuddyList.size(); i++) {
                        String currBuddy = (String) thisUsersBuddyList.get(i);
                        if (currBuddy != "" && currBuddy != null) {
                            sender.println(currBuddy);
                    sender.println("ENDBUDDYLIST");  // let client know we're done sending client buddy list
            if (clientMessage.toUpperCase().startsWith("ISONLINE")) {
                String usrToCheck = clientMessage.substring(8).trim();
                if (isOnline(usrToCheck)) {
                    sender.println("YES "+usrToCheck);
                } else {
                    sender.println("NO "+usrToCheck);
            if (clientMessage.toUpperCase().startsWith("ISAWAY")) {
                String usrToCheck = clientMessage.substring(6).trim();
                if (isUserAway(usrToCheck)) {
                    sender.println("Z "+usrToCheck);  // is away
                } else {
                    sender.println("X "+usrToCheck);  // not away
            if (clientMessage.toUpperCase().startsWith("CLIENTAWAY")) {
                String usrToCheck = clientMessage.substring(10).trim();
                if (!usrToCheck.trim().equals("")) {
                    setClientAsAway(usrToCheck);
            if (clientMessage.toUpperCase().startsWith("CLIENTBACK")) {
                String usrToCheck = clientMessage.substring(10).trim();
                if (!usrToCheck.trim().equals("")) {
                    setClientAsBack(usrToCheck);
            // Exit the clients connection to the server.
            if (clientMessage.toUpperCase().startsWith("EXIT")) {
                sender.println("GOODBYE");
                this.close();
            if (clientMessage.toUpperCase().startsWith("WHOISONLINE")) {
                whoisOnline();
            if (clientMessage.toUpperCase().startsWith("DISPATCHIM")) {
                String imStr = clientMessage.substring(1).trim();
                String to = imStr.substring(0,imStr.indexOf(" ")).trim();
                String imMsg = imStr.substring(imStr.indexOf(" ")).trim();
                dispatchIM(to,imMsg);  
          }  // end while is connected
        } // End run method
         public synchronized void addIMToQueue(String from, String msg) {
             instantMessage im = new instantMessage(from,msg);
             imQueue.addLast(im);
         private synchronized void getInstantMessages() {
             while (!imQueue.isEmpty()) {
                 instantMessage tmpMsg = imQueue.remove();
                 String tmpHandle = tmpMsg.getHandle();
                 String tmpImMsg = tmpMsg.getMsg();
                 sender.println("L "+tmpHandle+" "+tmpImMsg);
             sender.println("IMPOPDONE");
         private void dispatchIM(String to, String m) {
            for (int i = 0; i < MAX_CONNECTIONS; i++) {
                if (t[i] != null) {
                    if (t.username.trim().equals(to)) {
    pmClientHandler x = t[i];
    PrintStream ps = x.sender;
    ps.println("IMMSG "+this.username+" "+m);
    * Method will relay back to client a list of who's online. When it's finished
    * the command DONELISTING is dispatched.
    private void whoisOnline() {
    for(int i=0; i < MAX_CONNECTIONS; i++) {
    if (t[i] != null && t[i].username.trim() != "")
    sender.println(t[i].username);
    sender.println("DONELISTING"); // so client knows we're done
    } // END whoisOnline METHOD
    private boolean isOnline(String user) {
    boolean isOn = false;
    for (int i = 0; i < MAX_CONNECTIONS; i++) {
    if (t[i] != null && t[i].username.trim().equals(user.trim())) {
    isOn = true; break;
    return isOn;
    private boolean isUserAway(String user) {
    boolean tmpIsAway = false;
    for (int i = 0; i < MAX_CONNECTIONS; i++) {
    if (t[i] != null) {
    if (t[i].username.trim().equals(user)) {
    if (t[i].userAway) {
    tmpIsAway = true;
    break;
    } else {
    break;
    return tmpIsAway;
    private void setClientAsAway(String user) {
    //this.userAway = true;
    for (int i = 0; i < MAX_CONNECTIONS; i++) {
    if (t[i] != null) {
    if (t[i].username.trim().equals(user)) {
    t[i].userAway = true;
    private void setClientAsBack(String user) {
    //this.userAway = false;
    //this.userBusy = false;
    //this.userInvisible = false;
    for (int i = 0; i < MAX_CONNECTIONS; i++) {
    if (t[i] != null) {
    if (t[i].username.trim().equals(user)) {
    t[i].userAway = false;
    t[i].userBusy = false;
    t[i].userInvisible = false;
    private boolean isUserBusy(String user) {
    boolean tmpIsBusy = false;
    for (int i = 0; i < MAX_CONNECTIONS; i++) {
    if (t[i] != null) {
    if (t[i].username.trim().equals(user)) {
    if (t[i].userBusy) {
    tmpIsBusy = true;
    break;
    } else {
    break;
    return tmpIsBusy;
    private boolean isUserInvisible(String user) {
    boolean tmpIsInvisible = false;
    for (int i = 0; i < MAX_CONNECTIONS; i++) {
    if (t[i] != null) {
    if (t[i].username.trim().equals(user)) {
    if (t[i].userInvisible) {
    tmpIsInvisible = true;
    break;
    } else {
    break;
    return tmpIsInvisible;
    * Method will close the connection to the server.
    * It will also free up array location for any new connections
    private void close() {
    if (isConnected) {
    try {
    connection.close();
    isConnected = false;
    userValidated = false;
    System.out.println("User " + username + " has disconnected from the Pita Messenger server.");
    for(int i=0; i < MAX_CONNECTIONS; i++)
    if (t[i]==this) t[i]=null; // set array element to null so we can accept another
    // connection had we been maxed out
    } catch (IOException e) { }
    } // end pmClientHandler class
    Now finally for my problem...this all works EXACTLY as expected when I telnet to the server. My client GUI application has an issue though. When I want to send an IM to a particular user...the thread code above that listens for *DISPATCHIM* get's who the IM is to and what the message is in the following protocol format *DISPATCHIM to msg* and call the following private method:private void dispatchIM(String to, String m) {
    for (int i = 0; i < MAX_CONNECTIONS; i++) {
    if (t[i] != null) {
    if (t[i].username.trim().equals(to)) {
    pmClientHandler x = t[i];
    PrintStream ps = x.sender;
    ps.println("IMMSG "+this.username+" "+m);
    Basically, if not obvious, what I'm doing here is iterating through the array of client connection threads and finding the client thread that belongs who this message is to, and accessing the sender object and dispatching to the IM to that client. Again, all works perfectly in telnet. However, my client GUI is not recieving any data. With all my testing, it seems that I am only able to access and modify strings and boolean variables, however it's like I've lost the sender object (only in my GUI app). This is really bugging the hell out of me and I've spent days trying to figure this out. Something is just not right. My client app has a dispatcher thread that constantly listens for incoming connects (if a buddy is online, or an instant message). This is the run method of that class:public void run() {
    String data;
    while(true) {
    try {
    try {
    data = reciever.nextLine();
    if (!data.trim().toUpperCase().startsWith("YES") && !data.trim().toUpperCase().startsWith("NO") && !data.trim().toUpperCase().startsWith("X") && !data.trim().toUpperCase().startsWith("Z")) {
    System.out.println("Foreign command: "+data);
    } catch (Exception e) { System.out.println("ERR: "+e); break; }
    // pass any data returned at any time during to the serverListener method
    serverListener(data);
    } catch (Exception e) { }
    * Method is used to handle all incoming messages from the server.
    private void serverListener(String data) {
    if (data.trim().toUpperCase().startsWith("IMMSG")) {   // Handle incoming im
    String imStr = data.substring(1).trim();
    String imFrom = imStr.substring(0,imStr.indexOf(" ")).trim();
    String imMsg = imStr.substring(imStr.indexOf(" ")).trim();
    // Check to see if we have any IM sessions open already
    if (isChatWithBuddyOpen(imFrom)) {
    imWindow thisIMSession = getIMSession(imFrom);
    thisIMSession.appendBuddyMessage(imMsg);
    thisIMSession.setVisible(true);
    } else {
    newIMSession(imFrom);
    imWindow thisIMSession = getIMSession(imFrom);
    thisIMSession.appendBuddyMessage(imMsg);
    thisIMSession.setVisible(true);
    // Garbage collection for old IM sessions
    if (!imSessions.isEmpty()) {
    for (int i = 0; i < imSessions.size(); i++) {
    imWindow isGarbageIM = imSessions.get(i);
    if (isGarbageIM == null || isGarbageIM.chatBuddy.trim().equals("")) {
    imSessions.remove(i);
    } else if (data.trim().toUpperCase().startsWith("Z")) {  // Handle user is away response
    String userResponse = data.substring(1).trim();
    clientGUI.handleUserAwayMsg(userResponse, true);
    } else if (data.trim().toUpperCase().startsWith("X")) {  // Handle user is online response
    String userResponse = data.substring(1).trim();
    clientGUI.handleUserAwayMsg(userResponse, false);
    } else if (data.trim().toUpperCase().startsWith("ISBUSY")) { // Handle user is busy response
    } else if (data.trim().toUpperCase().startsWith("NOTBUSY")) { // Handle user is not busy
    } else if (data.trim().toUpperCase().startsWith("ISINVISIBLE")) { // Handle user is invisible
    } else if (data.trim().toUpperCase().startsWith("NOTINVISIBLE")) { // Handle user is  not invisible
    } else if (data.trim().toUpperCase().startsWith("YES")) {  // Handle user is online
    String userResponse = data.substring(3).trim();
    clientGUI.handleUserOnlineMsg(true,userResponse);
    } else if (data.trim().toUpperCase().startsWith("NO")) {  // Handle user is offline
    String userResponse = data.substring(3).trim();
    clientGUI.handleUserOnlineMsg(false,userResponse);
    } // end serverListener method
    It's like my receiver object gets NOTHING. Again, this only occurs with my GUI app, in telnet. Can anyone PLEASE advise as to what might be occuring. Thanks very much. If you might really be able to help I could post the entire app and server zipped up so that you can poke through. If you help me figure this out and I understand why it's not working, I'll buy you a case of your favorite beer ;) Thanks!                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                

    A couple of things.
    In future Networking related questions should be posted into the Networking forum.
    There is too much code here and too much page width. It's a bit overwhelming. You'll need to narrow this down a bit. From looking so far I see some potential
    portocol related issues. Like the readLine. Are you sure you are always writing line breaks on the other side? And then there's the substring bits which are
    going to be brittle.
    My suiggestion would be to trace things through and be able to point out exactly where the code is getting stuck/failing. Even getting it narrowed down to a method
    would be very helpful.

Maybe you are looking for

  • Continue script but hang in a speech

    I'm trying to do a script for a campaign in UCCX 7.0.1_Build168, make calls with 'Place Call' phone numbers extracted from a. 'Xml', and when the call is received the delivery to a 'CSQ' to the receiving agent. While waiting for an agent is free, you

  • Bounce file exceeds maximum size. How to change CAF

    I'm new at editing recordings. I only record my speaking engagements. They are rarely under one hour. When I tried to "share" to my iTunes, I got an error message that says "The bounce file exceeds the maximum file size. Please change the format to C

  • HT4623 I have updated my iPhone 5 but after this update it does not accept charging

    Dear Sir/Ma'am, I have update my iphone 5 software with iOS 7 but after this update it does not accept the charger or neither any charging ? I need to know how to solve this issue please. Thank you

  • Percentage pie chart whose query return just one value

    Hi, I have a requirement which is to display a pie chart that shows the relative percentage of based on a particular row's values. Here the SQL query return just one value to generate the chart, however Apex is creating its own seemingly random value

  • Opening Movie Menu crashes PE11, why?

    Another problem!  A probably buggy one.   I'm trying to use Tools > Movie Menu to add Main Menu and Scenes menu but each time I open it, PE11 crashes.   It may be because what I'm trying to do isn't straightforward.  Namely, I had put together from s