Keep opened socket connection?

Hi,
My Java application communicates with server on average every 3 seconds. I wonder if it is a good idea to keep an opened socket connection to the server and don't open new connection for each request. The problem with this is that if in the meantime is connection aborted, java.net.SocketException is throwned.
What do you think about keeping opened connection? Is appropriate to work with opened connections or to open new connection for each new request? How do you solve in your applications situation when communication is irregular but frequent.
Thanks.

I had one more question on this topic relating to capture and processing exceptions. Communication between client and server I accomplish wit these three classes:
- ClientRequest - represents client request to the server
- Communication - gets ClientRequest and socket connection to the server and sends the request to the server
- ServerResponse - represents response returned from the server
Now If Communication class gets dead connection it can't work and throws an exception. We discussed that I should find out the situation and suitably respond to this situation.
My question is whether the method for reconnection should call:
a) Communication class
b) class that uses the Communication class?
c) somebody else (?)
In case a) there is an advantage that all is in one place and Communication class user does not have to worry about anything beause class will try reconnect itself (if second attempt fails, method throws another exception). The advantage of b) is that the user needs, he can respond to this situation and do some another action.
Thanks.

Similar Messages

  • Cannot open socket connection on port 443

    Hi!
    Our server is running on Port 443.
    When I try to Connect from the BlackBerry 9300, an exception is thrown "cannot open socket connection on port 443"
    Can any one please help me in finding the solution to enable the port 443.
    Thank you in advance!
    Regards,
    Vinay

    I assume that you have verified that you can login to the ftp site using a regular ftp client (e.g. Fetch) on the Mac?

  • Is it wise to keep the socket connection open?

    When u have a bunch of HTTP requests coming in to a listener server socket, would it be safe to keep my JAVA socket connection open with KeepAlive or simply open/close at will? I thought of a connection of sockets as well. Thoughts? thx!

    It depends which socket your talking about
    The serversocket you want to always be open and listened to
    the sockets it spawns you should close when you've finished the transaction

  • Why does my computer keep opening netbios connections?

    netbiosd keeps opening connections to random IP addresses (usually an overseas ISP). Since installing LittleSnitch I've blocked 5 of these connections (2 ISP's in the US, 1 ISP in Poland, 1 ISP in the UK), and am starting to become concerned that I might have some kind of malware.
    I intalled ClamXav and checked the whole harddrive with the latest definition, but it didn't come up with anything.
    Any ideas?

    Using LittleSnitch I have received 3 alerts from netbiosd in the past week.
    I have denied all of them after a cursory lookup of the IP addresses using various tools (whois, traceroute)
    The blocked entries were:
    69.70.43.102, port 137
    82.186.105.146, port 47863
    125.239.135.130, port 53659
    Any idea why netbiosd is trying to contact these IP addresses? I would assume this is along the same lines. I'm getting to the point where I am willing to disable/block netbiosd to keep these messages from coming up, but I don't want to risk undue wear and tear by not sleeping.
    I do have screen sharing enabled, but am always behind a firewall. <---don't know if this is related. File and print sharing are not enabled.
    Lion 10.7.4, fully updated. MBP/i7 2.6/8GB

  • Can not open socket connection

    Hi,
    This code doesn't work on my phone but it works on emulator. What should the reason be? What should I do?
    SocketConnection sc =
    (SocketConnection)Connector.open("socket://MY_SERVER_IP:1111");

    Hi,
    The problem might be becoz of the NAT (Network Address Tranlation). Coz if your server is behind some NAT then, your mobile ll get an ip that all other mobile conneted to that server througth that specific service provider.
    In short, using socketConnection to connect a server, if the server is behind a NAT then all the mobile client connecting to that server ll get same ip, so server dont know to which ip it shold send the response.
    tell me if it helps

  • Too many open socket connections causing ColdFusion to crash?

    I’m currently working on an e-commerce site which sends and receives information to/from the client’s order management system via XML over a TCP/IP socket.  It uses a very old java-based custom tag called CFX_JSOCKET (which appears to have been written in 2002) to open the socket, send the data, and get the response.  The code that calls the custom tag and sends/receives data from the OMS pre-dates my working on the site, but its always worked, so I haven’t paid it much attention.
    Back in the summer of 2009 we started experiencing issues with ColdFusion (v.7 on Window 2003 at the time) locking up on a more and more frequent basis, until it ultimately became a daily issue.  After extensive research we narrowed the issue down to the communication between the web server and our client’s order management server.  It seemed the issue with ColdFusion hanging was either related to there being too many connections open, or to these connections hanging and resulting in dead threads.  This an educated guess based on a blog post I’d seen online, not actual monitoring of either CF or the TCP/IP connections.  As soon as we dialed back the timeout on the CFX_JSOCKET tag from 20 seconds to 10, the issue disappeared, so we left it at that and moved on.
    Fast forward to this January. The site is hosted at a new location, on a 64-bit Windows 2008 box running ColdFusion 9.  Over the years traffic on the site has continued to grow.  The nature of the clients business means that August and January are their business times of the year (back to school for college kids) and in January ColdFusion once again started locking up on an almost-daily basis.  
    One significant difference is that the address cleansing software that previously ran on the box and was used to verify shipping addresses is not available for 64-bit, so when we moved to the new server last summer, that task was moved to the client’s order management software and handled via XML like all other interaction with that system. However, while most XML calls to that server (order input, inventory check, etc) take under a second to complete, the address cleansing call regularly takes over 5 seconds to return data, and frequently times out. 
    Once we eliminated the address cleansing call from the checkout process, ColdFusion once again stopped locking up regularly.  So it appears that once again it’s the communication between the web server and the order management server that’s causing problems. We currently have that address cleansing call disabled on the web site in order to keep ColdFusion from crashing, but that’s not a long term solution.
    We don’t have, nor can I find online, the source code for the CFX_JSOCKET custom tag, so I decided I’d write some CF code utilizing the java methods to open the socket, send the data, get the response, and close the connection.  My test code is working fine (under no load).  However, in trying to troubleshoot an issue I had with it, I started monitoring the TCP/IP connections using TCPView.  And I noticed that all the connections to the order management server, whether opened via the custom tag or my new code, remain open in either a TIME_WAIT or FIN_WAIT2 status for well over 2 minutes, even though I know for a fact that my new code is definitely closing the connection from the web server side. 
    They do all close eventually, but I’m wondering 1. Why they’re remaining open that long; 2. Is that normal; and 3. If all these connections remaining open could be what’s causing ColdFusion to choke. 
    Does this sound plausible?  If so, does anyone have any suggestions/recommendations about how to fix it?  My research seems to indicate this might be a matter of the order management system not closing the connection on its end, but I’m in way over my head, and before I go to client and tell them it’s their OMS causing the issue, I need to feel a little more confident that I’m on the right track. 
    Any help or advice would be very greatly appreciated.  And thanks for taking the time to read through my long-winded explanation of the problem.
    Set-up details:
    ColdFusion Version: 9,0,0,251028  Standard 
    Operating System: Windows Server 2008 
    Java Version: 1.6.0_14 
    Java VM Name: Java HotSpot(TM) 64-Bit Server VM 
    Java VM Version: 14.0-b16 
    Thanks,
    Laurie

    Hi Laurie,
    Not aware of custom tag called CFX_JSOCKET. I guess the process you described very well is consuming a resource then you are getting a problem. Trick is what parameter to adjust. Perhaps you are running out of one the threads in CFadmin > Server Settings > Request Tuning.
    I expect if you enable CF Metrics logging where you can log the threads and other resources then you can find out which parameter needs adjusting. Let me know if you want some details on enabling CF Metrics. Perhaps others will have much better idea than me and help without the overhead of logging.
    The other interesting thing is you are using CF9.0.0. Do you have some reasons for not being on updater1 CF9.0.1?
    HTH, Carl.
    PS I posted before however seems to have gone, just hope does not come back and then I have posted twice.

  • Keeping a socket connection alive

    Hi, here is an interesting situation which I am trying to deal with. Basically what I want to have happen is the following:
    Have a ServerSocket (called server) running and acception connections from users.
    But where the catch comes in, is I want to be able to shut-down and restart the server without any of the connected users being disconnected.
    One possible way I thought of doing this was using a middle-man style application (called client) which has a socket link betweeen it and the server, and another socket link between it and the user. But the server needs to be able to directly talk to the user and this is where I get stuck.. Basically then if the server gets shutdown, the user still has the active connect between it and the client, and when the server gets reconnected the link between the client and server is restored..
    Any ideas? I don't know even if this middle-man style application is the best approach.
    Thanks,
    Derrick

    How about having the server split in two, a lower
    half that handles connections and an upper half that
    handles the actual mechanism of your server's
    functions. Make the lower half public, it knows
    whether the upper half is alive or not, and keeps a
    list of connections, buffering requests that may come
    in while the upper half is being restarted.
    you could do it in two processes, one for each half,
    but you try to make the lower half simple and ensure
    it runs forever.
    the upper half could come and go as it (and you) need
    it to.
    now the upper half would run on a private port and
    only the lower half would know about it.Yes, this is what I have done, but when the upper half wants input from the user in calles the inputsteam.. but the lowerhalf doesn't know that it has to then request the info from the user.. this is the problem I'm stuck at :(

  • Error opening socket connection to Thirdparty vendor

    Does (socket.isConnected()){}, works fine in JDK 1.4 ??

    It works fine in all versions where it's present but it doesn't do what you're probably expecting. All it does is tell you whether you have ever connected the socket. After you've constructed a Socket with an InetAddress:port, or called connect(), or accepted it from a ServerSocket, isConnected() will return true forever, even after you close it.
    It's not an indicator of the state of the connection, it's an indicator of what you have done to the socket, i.e. the endpoint of the connection.

  • Sorry, My Help Viewer keeps opening AFP connection.

    Sorry I had my letters mixed up on that last post. Feel free to delete that. I just got a new Imac and set up my first ever network. Being a rookie at this I can't quite figure this one out. Everytime I open Mac Help the Help Veiwer tries to connect to my older computer. Its kind of annoying because I have to cancel and wait for the spinning color wheel of death to stop before I can get answers. With the new I-life, I've got pleny of questions. Can anybody help me with this? Thanks in advance, Keith

    I have done several migrations (10+) and not experienced this one before. Once you have done all the 'normal' precautions (repairing permissions using Disk Utilities and dragging the Help Viewer preferences com.apple.helpviewer.plist to the desktop), then we have to look further.
    If the above do not help, can we have some more info? I take it you did migrate your data from your old computer. Was it done after initial setup or during? Could you also tell us from which model to which, and if the older computer was running Tiger, or an older system.
    Karn.

  • My Help Viewer keeps opening APV connection?!

    I just got a new Imac and set up my first ever network. Being a rookie at this I can't quite figure this one out. Everytime I open Mac Help the Help Veiwer tries to connect to my older computer. Its kind of annoying because I have to cancel and wait for the spinning color wheel of death to stop before I can get answers. With the new I-life, I've got pleny of questions. Can anybody help me with this? Thanks in advance, Keith

    I have done several migrations (10+) and not experienced this one before. Once you have done all the 'normal' precautions (repairing permissions using Disk Utilities and dragging the Help Viewer preferences com.apple.helpviewer.plist to the desktop), then we have to look further.
    If the above do not help, can we have some more info? I take it you did migrate your data from your old computer. Was it done after initial setup or during? Could you also tell us from which model to which, and if the older computer was running Tiger, or an older system.
    Karn.

  • Help in keeping a Persistent Socket connection

    Hello All,
    Pardon me, this is a silly question.. I have a Client who is using socket connection to connect to a server.. Currently the client is not maintaining a persistent connection. IT connects to t he server ,sends & receives messages from the server and then closes the connection. How do I keep the Socket connection alive so I can get the messages sent from the server asynchronously ???
    thanks for your time

    Thanks for your reply. Can I use thread to keep the connection alive.??? If so , It would be really helpful if U can show me a sample code......
    Below is my piece of code...
    try{
    socket_Client = new Socket(name_server,portNumber);
    InputStream input = socket_Client.getInputStream();
    InputStreamReader in2 = new InputStreamReader(input);
    BufferedReader in = new BufferedReader(in2);
    getMessages(in); //this method gets the messages from the server
    } catch ( Exception e)
    } finally {
    socket_Client.close()
    thanks again

  • Urgent --- Persistent socket connection?

    Hi, I have a question about the persistency of a Java Socket connection. Is it a valid idea to keep a java socket open for a long time? If so, what special care do I need to take?
    My Java TCP/IP client runs as a NT service. It keeps getting input messages every few seconds, then send it thru a socket connection to a TCP/IP server. In order to avoid the overhead of opening and closing the socket every time the client gets a message to send, I want to keep the socket connection open and reuse it.
    I was able to send hundreds of messages thru this way, then after a while, for no apparent reason,
    the socket stops working, I typically get an exception like this:
    java.net.SocketException: Connection Shutdown: JVM_recv in socket input stream read
    at java.net.SocketInputStream.socketRead(Native Method)
    at java.net.SocketInputStream.read (SocketInputStream.java:90)
    at java.net.SocketInputStream.read (SocketInputStream.java:71)
    at java.io.InputStreamReader.fill (InputStreamReader.java:163)
    at java.io.InputStreamReader.read (InputStreamReader.java:239)
    at java.io.BufferedReader.fill (BufferedReader.java:137)
    at java.io.BufferedReader.readLine (BufferedReader.java, Compiled Code)
    at java.io.BufferedReader.readLine (BufferedReader.java:329)
    My programs runs on NT4.0, single-threaded. Any input would be greatly appreciated.

    Is it a valid idea to keep a java socket open for a long time? If so, what
    special care do I need to take?Depends.
    First why keep it open? Your messages only arrive every couple of seconds, does opening/closing the connection take longer than that?
    If you must then the complication you must deal with is that your code must deal with re-establishing the connection when it does fail. Opening/closing it every time avoids that issue. The connection will fail, because computers fail, networks fail and people make mistakes. Which doesn't mean that you shouldn't but merely that you should consider the implications of why you need to keep it open.

  • Socket Connection Error

    Hi,
    I m facing some strange issues in a java file. The requirement is something like, i need to process some business operation , connect to a third party vendor and they need to process some operation in 10 secs and they reverted back with the result. The whole process should complete in 15 secs.
    So for the first time while connection to the third party it is working fine, but for the second time it fails and showing connection failed in the UI. When i retires it is successfully connects. i checked the log file, there it is throwing exceptions some of the time. Please find the piece of code below. From the third party there is no issues from them , all the operations sucessfully done from their side..
    try {
    // open socket connection
    socket = openSocketConnection(host, port, connectTimeOut, responseTimeout);
    if(socket.isConnected()){
    // some steps of business processing.....
    // write request
    // read response
    // set pipeline
    // set error status
    catch(SocketTimeoutException ste){}
    catch (UnknownHostException uhe) {}
    catch (SocketException soe) {}
    catch (Exception e) { }
    finally {
    try {
    if (socket != null)socket.close();
    } catch (Exception e) { }
    // method for connecting the server....
    openSocketConnection(String host, int port, int connectTimeOut, int responseTimeout) throws SocketTimeoutException, ServiceException,IOException {
    Socket socket = null;
    socket = new Socket();
    socket.bind(null);
    socket.connect(new InetSocketAddress(host,port),connectTimeOut);
    if (socket.isConnected()) {
                   socket.setSoTimeout(responseTimeout);
    } else {
         throw new ServiceException("Error opening socket connection to Third party Vendor.");<------- mostly in second time throwing exception, but when retires working fine...
    return socket;
    Can anyone please help me out for this.

    Remove the isConnected() test and associated code: it's contributing nothing here. If the socket itself throws an exception then you have a problem. At the moment all you have is a self-inflicted wound.
    You can also remove the bind(null) call.

  • How to enable socket connection?

    I have allowed INTERNET permission, but my socket still blocked.
         <uses-permission android:name="android.permission.INTERNET" />
    If I compile apk with -debug tag, then socket connection works, but my application runs very slow.
    And I dont want to publish a release version with all my debug messages.
    What is the standard way to open socket connection?
    Thanks

                   var s:Socket=new Socket();
                    s.connect("ip_address", "port_number");
                    s.addEventListener(Event.CONNECT, function(event:Event):void{
                        trace('connected!');
                    s.addEventListener(IOErrorEvent.IO_ERROR, function(event:IOErrorEvent):void{
                        trace('error! ' + event.errorID);
                    s.addEventListener(ProgressEvent.SOCKET_DATA, function(event:ProgressEvent):void{
                        var str:String=(event.currentTarget as Socket).readUTF();
    There are examples out there.  Fire up Google Search .

  • Studio Creator, Socket Connection to External Device

    I am porting an existing & successful project from Netbeans 3.6 into Studio Creator to take advantage of some of the tools in the IDE for this application. The project requires opening a socket connection from the Server PC to an external Device (PLC) that is a Client on a static IP & a dedicated fixed port.
    I am struggling to get past some security settings specific to AccessControlExceptions. Here is the code method being used to test:
    public String button1_action() {
    // Call methods to open connection, init streams, send command, and close connection.
    try {
    // Open Socket up and accept client connection
    ipSocketObject = new ServerSocket(port);
    bfSocket = ipSocketObject.accept();
    // Establish Streams
    is = new BufferedReader(new InputStreamReader(bfSocket.getInputStream()));
    os = new PrintWriter(bfSocket.getOutputStream(), true);
    System.out.println("Got to here...");
    // Clear the msCounter #13002
    os.println("r13002=0");
    pattern = "13002";
    do{ret=is.readLine();} while ((ret.indexOf(pattern)) ==-1);
    is.close();
    os.close();
    bfSocket.close();
    ipSocketObject.close();
    } catch (IOException e) {
    e.printStackTrace();
    return null;
    The Socket Connection is established, but the command string is not processed before Studio Creator generates a AccessControlException Fault. I have experiemented putting in a SocketPermission statement with out success.
    Is anyone aware of some sample code I might be able to review for opening socket connections to clients in a Studio Creator Application? Please excuse this request if too rudimentary- I am an Industrial Controls guy by trade... :)

    Sorry I know of no such application at this time, and unfortunately have not done socket work myself for many moons....
    What JDK was your previous application written under? I googled for AccessControlException and socket and seems that sometimes accounts for some issues... you can also search for that combination in the forum advanced search and might find something there.... one more long shot suggestion based upon your statement "the command string is not processed".... could it be that you need to flush the stream...?
    Sorry I don't have more to offer...
    v

Maybe you are looking for

  • Different LOVs in af:query and af:form for the same VO attribute

    Hi, We need to display different LOVs in af:query and af:form for the same attribute in VO. Is it possible to use LOV Switcher for this ? What condition can we use in LOV Switcher attribute to check if it is View Critearia row or VO row ?

  • Problem: Sharing Folders with iMac and winXP

    We have been running a small workgroup sharing so far two winxp machines over a wifi-modem-router-switch. The two pc share folders without problem. I have now proudly made the switch over to using Apple iMac. Whilst the iMac experience is fantastic,

  • Fastest Apple computer with OS 9

    What would be the highest computer that apple made which could handel OS 9? I know it is the quick silver G4 (Maybe one with the mirror door), but which one? Thanks

  • Creating a recordset filtered by login credentials

    Hello everyone... I'm really hoping I can get an answer to this... I've created a login page using the "login user" behavior and it works perfectly. But I'm having trouble identifying the user after they've logged in. For example, I may want to greet

  • [SOLVED][glibc] A lot of conflicts. Already existing files.

    I'm trying to update my system with a ''pacman -Syu''. But I keep getting a conflict. Targets (12): kernel-headers-2.6.31.5-1 glibc-2.11-1 binutils-2.20-2 bzip2-1.0.5-5 dhcpcd-5.1.3-1 fakeroot-1.14.3-1 gcc-4.4.2-3 gcc-libs-4.4.2-3 hal-0.5.13-3 kernel