Socket connection timeout

I have a simple threaded client application to connecting to the server
which is also threaded. I am using the following code to prevent(reduce)
connection timeouts, but it doesn't seem like timeout period elapses
before exception is thrown on the client side. Any ideas? Exception
occurs way before 10 seconds as specified in the code below.
InetAddress addr = InetAddress.getByName(this.serverName);          
SocketAddress sockaddr = new InetSocketAddress(addr,this.port);
Socket socket = new Socket();
socket.connect(sockaddr,10000);
The exception I get on the client side is:
java.net.ConnectException: Connection refused: connect
Thanks

The timeout kicks in if the other end hasn't responded within the period. In this case the other end has refused the connect attempt, probably because nothing is listening on the requested port. This can happen well within the timeout period, as you have experienced.

Similar Messages

  • How to make a socket connection timeout infinity in Servlet doPost method.

    I want to redirect my System.out to a file on a remote server (running Apache Web Server and Apache Tomcat). For which I have created a file upload servlet.
    The connection is established only once with the servlet and the System.out is redirected to it. Everything goes fine if i keep sending data every 10 second.
    But it is required that the data can be sent to the servlet even after 1 or 2 days. The connection should remain open. I am getting java.net.SocketTimeoutException: Read timed out Exception as the socket timeout occurs.
    Can anyone guide me how to change the default timeout of the socket connection in my servlet class.
    Following is the coding to establish a connection with the Servlet.
    URL servletURL = new URL(mURL.getProtocol(), mURL.getHost(), port, getFileUploadServletName() );
    URLConnection mCon = servletURL.openConnection();
    mCon.setDoInput(true);
    mCon.setDoOutput(true);
    mCon.setUseCaches(false);
    mCon.setRequestProperty("Content-Type", "multipart/form-data");
    In the Servlet Code I am just trying to read the input from the in that is the input stream.
    public void doPost(HttpServletRequest req, HttpServletResponse res)
    throws ServletException, IOException
    BufferedInputStream in = new BufferedInputStream(req.getInputStream());
    byte [] content = new byte[1024];
    do
    read = in.read(content, 0, content.length);
    if (read > 0)
    out.write(content, 0, read);
    I have redirected the System.out to the required position.
    System.setOut(........);
    Can anyone guide me how to change the default timeout of the socket connection in my servlet class.

    I am aware of the setKeepAlive() method, but this can only used with the sockets. Here i am inside a servlet, have access to HTTPServletRequest and HTTPServletResponse and I don't know how to get access to the underlying sockets as the socket handling will be handled by the tomcat itself. If I am right there will be method in the apache tomcat 6.0.x to set this property. But till now I am not getting it.

  • Sockets connection timeout

    I'm trying to open a socket on a machine(ip address). It works fine when the machine is up, but it takes about a minute for the socket to return an exception if the maching is down.
    I've tried opening the socket in a separate thread (as is the only suggestion I found till date), and tried to time it out from the thread running it. But, this doesn't work.
    Does anyone have any solution other than the 'thread' solution??
    Any help would be greatly appreciated.

    From the javadocs for setSoTimeout
    ... a read() call on the InputStream associated with this Socket will block for only this amount of time...
    It doesn't say anything about connecting.
    And from "Unix Network Programming" by Stevens
    ..three ways to place a timeout on ... a socket
    1. Call alarm...
    2. Block waiting for I/O in select, ... instead of blocking in a call to read...
    3. Use the newer SO_RDVTIMEO and SO_SNDTIMEEO ... not all implementations support these two socket options.
    All three techniques work with input and output operations (e.g. read, write, and...) but we would also like a technique that we can use with connect, ... select can used to place a timout on connect only when the socket is is in a nonblocking mode...
    Based on the above I don't believe setSoTimeout() is going to affect the timeout of a connect.
    Additionally can one connect a Socket after creation? setSoTimeout() is not static, so the socket instance has to exist before calling it. But I don't see a connect method (nor a way to set host and port after initialization) so how could it affect the connect timeout?

  • Socket proxy timeout

    Hi,
    I'm currently using:
    mysock.connect(sockaddr, 2000);
    to set socket connection timeout.
    Everything works fine until i set a proxy:
    System.setProperty("socksProxySet", "true");
    System.setProperty("socksProxyHost", "proxy");
    System.setProperty("socksProxyPort", "port");
    Can i also set connection timeout for the proxy?

    ejp wrote:
    Oops I agree you are correct, it's there in 1.5 too. But does that propagate the 'closed' flag back to Socket?I think so, but I'm not sure. PlainSocketImpl extends SocketImpl. SocketImpl has a reference to the Socket, and close in PlainSocketImpl has this comment:
    * We close the FileDescriptor in two-steps - first the
    * "pre-close" which closes the socket but doesn't
    * release the underlying file descriptor. This operation
    * may be lengthy due to untransmitted data and a long
    * linger interval. Once the pre-close is done we do the
    * actual socket to release the fd.
    */It's hard to see if it call close on the Socket since socketPreClose and socketClose invokes native methods.

  • Help Set Proxy connection timeout

    Hi,
    I'm currently using: mysock.connect(sockaddr, 2000);
    to set socket connection timeout.
    Everything works fine until i set a proxy:
    System.setProperty("socksProxySet", "true");
    System.setProperty("socksProxyHost", "proxy");
    System.setProperty("socksProxyPort", "port");
    Can i also set connection timeout for the proxy?
    Message was edited by:
    Robotto

    Everything works fine until i set a proxy:are you not able to connect to the server? Whats the issue?

  • Shorting the timeout for socket connection

    Hi everyone, i've got a client who owns a handle to a remote object. When the remote object quits, accesing it through a method invocation throws a java.net.SocketTimeoutException: Read timed out. That's fair, what's up is that it lasts about six seconds in sending it, and i would like to shorten the time it waits until it realises it can't connect. I've tried with sun.rmi.transport.connectionTimeout and sun.rmi.transport.tcp.readTimeout, and no success. Any idea?
    Thanks in advance.

    The "sun.rmi.transport.proxy.connectTimeout" parameter works only when HTTP is used.
    We do it manually by utilizing RMI client and server socket factories and setting socket options as appropriate. For the connect timeout, there is connect(SocketAddress endpoint, int timeout) method of the Socket class. With this approach, the application has a full control over sockets used by the RMI engine.

  • Connection timeout with Apple WiFi devices

    Ok, here's the scenario.
    The important thing to remember is that all was working well, as happy as 'larry the lamb'. Being that I was running Snow Leopard on my MacBook Pro 8,3 while accessing the internet through my iPhone 4 using it's Personal Hotspot feature (with iOS 4.2.5/4.2.6 running on the iPhone 4). Internet thethering worked beautifully between the MacBook Pro & iPhone4 and all was well. Some time before this I had used the Time Capsule's WiFi for internet access with NO problems (when I had dedicated broadband), but then switched to using mobile tethering (personal hotspot feature).
    I then upgraded to OS X Lion 10.7 (11A511) the day it was released and did this over a friends fast internet connection using cable ethernet connection for quicker speed. While I was doing this, I also downloaded the latest iOS update for my iPhone 4 being iOS 4.3.4 (8K2).
    Then the problems started.. I have not been able to connect to the iPhone's Personal Hotspot, nor the Time Capsule's WiFi and neither the Airport Express unit  (that plugs straight into the power socket). All three devices say 'connection timeout'. Resetting them either physically (reset button) or through the Airport Utility using an ethernet link (in the case of time capsule and airport express) make no difference.
    I wish I never updated the iPhone iOS and previously put of updating it for the previous few updates because the tethering worked so well on it, therefore I would want to downgrade it to iOS 4.2.5/4.2.6 again (need to locate and re-download those two versions and accuire instructions - if anyone could help, would be very appreciated?).
    Now this is the strange thing:- Although I cannot connect to the Apple Time Capsule, Apple Airport Express and iPhone Personal Hotspot (getting the 'connection timeout' error all the time), I am however able to connect to a non-Apple device Vodaphone 3G WiFi point. The Vodaphone 3G device is a 3G USB mobile dongle that is plugged into it's own dedicated small WiFi base station.
    I am at a loss as to what is going on here?

    I can totally understand your frustration and it ***** that you are having to experience it. I do know that for me yesterday the Apple.com page was down all day. I could connect to any other website, but not the Apple.com website. However, that doesn't solve your issue.
    I would advise you to break down your issue by each component and then work to solving them one at a time. I would first look into getting your machine connected to the internet first. If you have no way of getting it connected to the internet without using the other devices you mentioned at your home network, then go to a friends or to a place where you can test your machine's ability to stay connected to the internet through a different network. This will allow you to rule out the posibility that the issue is isolated to your machine/OS. If you find yourself still having connectivity issues, then work on solving them before introducing your other devices to the problem.
    Once and if you solve the issue with your machine I would then start looking into your home network and the devices you are using (i.e. Time Capsule, Airport, etc.) and be sure to check to see if you have the latest updates for them: http://support.apple.com/downloads/#airport
    For my own network, I use a modem (ARRIS) and router (Linksys E2000) and have had no issues with any of my machines (running Lion) or any of my other devices (i.e. iPhones, iPods, printers, etc.) connecting to my Wi-Fi network. I do however have family and friends that are using the same devices as you, but are not having any issues. However, none of them are using their iPhone's HotSpot and neither myself or anyone else has updated to iOS 4.3.5.
    I truly wish I could be me more of help, but the truth of the matter is when dealing with networks that deal with many different devices there are just so many variables that can be at play in regards to the issue, that you truly just have to take it one step at a time until you isolate the source of the issue at hand.

  • Oracle 9.0.1 on Solaris/SPARC infinite connection timeouts

    Hello, All!
    I have the following system configuration:
    Solaris 5.9 Maintenance Update 4;
    Sun Ultra 10, 1 UltraSPARC IIi 440Mhz CPU, 1024M RAM;
    Oracle 9.0.1 (9i Release 1).
    The database was created with JServer option turned on (we're using the integrated CORBA functionality); archive log mode is OFF, database cache advice is ON.
    In a nutshell,
    ==============
    the problem is in really infinite connection timeouts of Oracle after a long time of inactivity (say, on Monday after two weekend days).
    Long description.
    =================
    Client-side symptoms.
    First, I tried to establish a connection to a published CORBA object, and received no response (I am already waiting for 1 hour 40 minutes).
    Then, I tried to connect to the database with SQLPlus, remotely:
    $ sqlplus /nolog
    SQL> CONNECT SYS/change_on_install@ORCL AS SYSDBA;
    All the same, I receive no reply. However, the listener is alive, I can establish a network connection to both ports 1521 and 2481. Client-side logs (specified via sqlnet.ora) say the following:
    =========== skipped ===========
    [09-АВГ-2004 10:27:24:770] nioqsn: entry
    [09-АВГ-2004 10:27:24:770] nioqsn: exit
    [09-АВГ-2004 10:27:24:770] nioqrc: entry
    [09-АВГ-2004 10:27:24:771] nsdo: cid=0, opcode=84, bl=0, what=1, uflgs=0x20, c
    [09-АВГ-2004 10:27:24:771] nsdo: rank=64, nsctxrnk=0
    [09-АВГ-2004 10:27:24:771] nsdo: nsctx: state=8, flg=0x400d, mvd=0
    [09-АВГ-2004 10:27:24:771] nsdo: gtn=127, gtc=127, ptn=10, ptc=2011
    [09-АВГ-2004 10:27:24:771] nsdofls: DATA flags: 0x0
    [09-АВГ-2004 10:27:24:771] nsdofls: sending NSPTDA packet
    [09-АВГ-2004 10:27:24:771] nspsend: plen=770, type=6
    [09-АВГ-2004 10:27:24:771] nttwr: entry
    [09-АВГ-2004 10:27:24:771] nttwr: socket 12 had bytes written=770
    [09-АВГ-2004 10:27:24:771] nttwr: exit
    [09-АВГ-2004 10:27:24:771] nspsend: 770 bytes to transport
    [09-АВГ-2004 10:27:24:772] nsdo: nsctxrnk=0
    [09-АВГ-2004 10:27:24:772] nsdo: cid=0, opcode=85, bl=0, what=0, uflgs=0x0, cf
    [09-АВГ-2004 10:27:24:772] nsdo: rank=64, nsctxrnk=0
    [09-АВГ-2004 10:27:24:772] nsdo: nsctx: state=8, flg=0x400d, mvd=0
    [09-АВГ-2004 10:27:24:772] nsdo: gtn=127, gtc=127, ptn=10, ptc=2011
    [09-АВГ-2004 10:27:24:772] nsdo: switching to application buffer
    [09-АВГ-2004 10:27:24:772] nsrdr: recving a packet
    [09-АВГ-2004 10:27:24:772] nsprecv: reading from transport...
    [09-АВГ-2004 10:27:24:772] nttrd: entry
    If I try to connect to the database locally, I receive the same result:
    $ sqlplus /nolog
    SQL> CONNECT / AS SYSDBA;
    -- no reply.
    Server-side symptoms.
    Oracle logs in ${ORACLE_BASE}/admin/ORCL have no entries referring the last two days. Oracle server debug log (specified via sqlnet.ora) says the following:
    ========== skipped ===================
    nttrd: socket 20 had bytes read=181
    nttrd: exit
    nsprecv: 181 bytes from transport
    nsprecv: tlen=181, plen=181, type=6
    nsrdr: got NSPTDA packet
    nsrdr: NSPTDA flags: 0x0
    nsdo: what=1, bl=2009
    nsdo: nsctxrnk=0
    nioqrc: exit
    nioqsn: entry
    nioqrc: entry
    nsdo: cid=0, opcode=84, bl=0, what=1, uflgs=0x20, cflgs=0x3
    nsdo: rank=64, nsctxrnk=0
    nsdo: nsctx: state=8, flg=0x420c, mvd=0
    nsdo: gtn=156, gtc=156, ptn=10, ptc=2019
    nsdofls: DATA flags: 0x0
    nsdofls: sending NSPTDA packet
    nspsend: plen=93, type=6
    nttwr: entry
    nttwr: socket 20 had bytes written=93
    nttwr: exit
    nspsend: 93 bytes to transport
    nsdo: nsctxrnk=0
    nsdo: cid=0, opcode=85, bl=0, what=0, uflgs=0x0, cflgs=0x3
    nsdo: rank=64, nsctxrnk=0
    nsdo: nsctx: state=8, flg=0x420c, mvd=0
    nsdo: gtn=156, gtc=156, ptn=10, ptc=2019
    nsdo: switching to application buffer
    nsrdr: recving a packet
    nsprecv: reading from transport...
    nttrd: entry
    nttrd: socket 20 had bytes read=770
    nttrd: exit
    nsprecv: 770 bytes from transport
    nsprecv: tlen=770, plen=770, type=6
    nsrdr: got NSPTDA packet
    nsrdr: NSPTDA flags: 0x0
    nsdo: what=1, bl=2009
    nsdo: nsctxrnk=0
    nioqrc: exit
    Oracle local client debug log (oracle enterprise manager runs on the same machine) says:
    ...nsevwait: nsevwait: nsevwait: nsevwait: nsevwait:
    nsevwait: nsevwait: nsevwait: nsevwait: nsevwait:
    nsevwait: nsevwait: nsevwait: nsevwait: nsevwait: ...
    ps -e -o "user,pid,pcpu,pmem,rss,vsz,args" says there're several (3) processes running as oracle, with "args" oracle_ORCL, which eat up nearly all available memory (they have "pmem" values of 25, 25 and 17 per cent, respectively). One of these processes has "pcpu" value varying from 97% to 100%, moreover, this is a user, NOT system time (according to sdtperfmeter, disk/page/swap activity is extremely low; system load holds at value of 4). Here is a sample vmstat output:
         cpu
    cs us sy id
    287 99 1 0
    285 100 0 0
    280 100 0 0
    272 100 0 0
    298 98 2 0
    275 99 1 0
    267 100 0 0
    307 97 3 0
    282 100 0 0
    270 100 0 0
    307 98 2 0
    287 100 0 0
    Here cs is the number of cpu context switches per second;
    us is cpu user time;
    sy is cpu system time.
    The question is: what oracle may be doing and how can I fix the problem?
    Thanks in advance.

    Now, 3 hours later, the first two (of three) connections got established, but subsequent database queries are in the same nearly dead state.
    CPU usage remains about 100%, system load 4.
    I know that oracle restart (and/or system restart) will cure the problem -- but only until next weekend.
    Can this be oracle misconfiguration?

  • Socket connection time Out - Sender File adapter (Intermittent Issue )

    Dear FrIends,
    In our sender file adapter i am getting the following issue:
    I have already places timout : 120 secs.
    This isssue is occuring intermittently.
    Error occurred while connecting to the FTP server "100.142.131.30:21": java.net.ConnectException: Socket connection timed out: 100.142.131.30:21

    Hi Renu,
    You need to increase the timeout Seconds and check.
    Run the report RSFTP002.
    and check whether the connection to FTP works. Provide the below parameters:
    user = <your ftp user>
    pwd = <your ftp pwd>
    host= <your ftp host/ip>
    command1 = <ls>
    RFC Dest = SAPFTP
    Compress = N
    If the issue still exists, then check  with your BASIS Team.
    http://www.sap2048.com/socket-and-connection-issues-in-java-web-services-1351.htm
    Thanks,

  • Webservice Connection Timeout Error in Sun Java System Application server

    I have a java code to connect to Ebay Shopping Webservice that uses the client stub generated through Axis. The code works fine when I run it from the main method of a stand alone Java application. Which means there is no issue with the Proxy settings or any other network setting that could block the webservice from my system. However when I use the same code inside a JSF based Web Application, a connection timeout error comes up. The Web application is deployed on the Sun Java System Application server. The stacktrace of the exception is
    java.net.ConnectException: Connection timed out: no further information
         at sun.nio.ch.SocketChannelImpl.checkConnect(Native Method)
         at sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:527)
         at com.sun.enterprise.server.ss.provider.ASClientSocketImpl.connect(ASClientSocketImpl.java:206)
         at java.net.Socket.connect(Socket.java:520)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:585)
         at org.apache.axis.components.net.DefaultSocketFactory.create(DefaultSocketFactory.java:153)
         at org.apache.axis.components.net.DefaultSocketFactory.create(DefaultSocketFactory.java:125)
         at org.apache.axis.transport.http.HTTPSender.getSocket(HTTPSender.java:191)
         at org.apache.axis.transport.http.HTTPSender.writeToSocket(HTTPSender.java:404)
         at org.apache.axis.transport.http.HTTPSender.invoke(HTTPSender.java:138)
         at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
         at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
         at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
         at org.apache.axis.client.AxisClient.invoke(AxisClient.java:165)
         at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
         at org.apache.axis.client.Call.invoke(Call.java:2767)
         at org.apache.axis.client.Call.invoke(Call.java:2443)
         at org.apache.axis.client.Call.invoke(Call.java:2366)
         at org.apache.axis.client.Call.invoke(Call.java:1812)
         at com.ebay.api.soap.ShoppingBindingStub.findProducts(ShoppingBindingStub.java:1217)
         at com.shopping.ebay.EbayServiceUtility.performEBaySearch(EbayServiceUtility.java:66)
         at searchProduct.SearchProductBean.search(SearchProductBean.java:98)
         at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
         at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:585)
         at com.sun.el.parser.AstValue.invoke(AstValue.java:151)
         at com.sun.el.MethodExpressionImpl.invoke(MethodExpressionImpl.java:283)
         at javax.faces.component.MethodBindingMethodExpressionAdapter.invoke(MethodBindingMethodExpressionAdapter.java:77)
         at com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:96)
         at javax.faces.component.UICommand.broadcast(UICommand.java:383)
         at javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:450)
         at javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:759)
         at com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:97)
         at com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:244)
         at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:113)
         at javax.faces.webapp.FacesServlet.service(FacesServlet.java:244)
         at org.apache.catalina.core.ApplicationFilterChain.servletService(ApplicationFilterChain.java:397)
         at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:278)
         at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:566)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:536)
         at org.apache.catalina.core.StandardContextValve.invokeInternal(StandardContextValve.java:240)
         at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:179)
         at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:566)
         at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:73)
         at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:182)
         at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:566)
         at com.sun.enterprise.web.VirtualServerPipeline.invoke(VirtualServerPipeline.java:120)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:939)
         at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:137)
         at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:566)
         at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:536)
         at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:939)
         at org.apache.coyote.tomcat5.CoyoteAdapter.service(CoyoteAdapter.java:239)
         at com.sun.enterprise.web.connector.grizzly.ProcessorTask.invokeAdapter(ProcessorTask.java:667)
         at com.sun.enterprise.web.connector.grizzly.ProcessorTask.processNonBlocked(ProcessorTask.java:574)
         at com.sun.enterprise.web.connector.grizzly.ProcessorTask.process(ProcessorTask.java:844)
         at com.sun.enterprise.web.connector.grizzly.ReadTask.executeProcessorTask(ReadTask.java:287)
         at com.sun.enterprise.web.connector.grizzly.ReadTask.doTask(ReadTask.java:212)
         at com.sun.enterprise.web.connector.grizzly.TaskBase.run(TaskBase.java:252)
         at com.sun.enterprise.web.connector.grizzly.WorkerThread.run(WorkerThread.java:75)
    The JDK version on my machine is 1.5.0_14. Can somebody point me as where I should be looking for errors?

    You need to delete all the files under the 'generated' directory to force the server to recompile them after the JDK upgrade. Also check in domain.xml and make sure the JVM parameter is pointing to the JDK that you have installed. It is also worthwhile to check asenv.conf to see which JDK that file is pointing to as well.

  • MYSQL connection timeout?

    Hi all, ive been trying to update mysql databases on localhost and everything work perfect, but then im trying todo that in hosting (in this case phpnet.us). Im getting connection timeout error
    com.mysql.jdbc.CommunicationsException: Communications link failure due to under
    lying exception:
    ** BEGIN NESTED EXCEPTION **
    java.net.ConnectException
    MESSAGE: Connection timed out: connect
    STACKTRACE:
    java.net.ConnectException: Connection timed out: connect
            at java.net.PlainSocketImpl.socketConnect(Native Method)
            at java.net.PlainSocketImpl.doConnect(Unknown Source)
            at java.net.PlainSocketImpl.connectToAddress(Unknown Source)
            at java.net.PlainSocketImpl.connect(Unknown Source)
            at java.net.SocksSocketImpl.connect(Unknown Source)
            at java.net.Socket.connect(Unknown Source)
            at java.net.Socket.connect(Unknown Source)
            at java.net.Socket.<init>(Unknown Source)
            at java.net.Socket.<init>(Unknown Source)
            at com.mysql.jdbc.StandardSocketFactory.connect(StandardSocketFactory.ja
    va:173)
            at com.mysql.jdbc.MysqlIO.<init>(MysqlIO.java:267)
            at com.mysql.jdbc.Connection.createNewIO(Connection.java:2739)
            at com.mysql.jdbc.Connection.<init>(Connection.java:1553)
            at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java
    :266)
            at java.sql.DriverManager.getConnection(Unknown Source)
            at java.sql.DriverManager.getConnection(Unknown Source)
            at palidino76.rs2.util.SQLHandler.createConnection(SQLHandler.java:20)
            at palidino76.rs2.Engine.run(Engine.java:147)
            at java.lang.Thread.run(Unknown Source)
    ** END NESTED EXCEPTION **
    Last packet sent to the server was 31 ms ago.
            at com.mysql.jdbc.Connection.createNewIO(Connection.java:2814)
            at com.mysql.jdbc.Connection.<init>(Connection.java:1553)
            at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java
    :266)
            at java.sql.DriverManager.getConnection(Unknown Source)
            at java.sql.DriverManager.getConnection(Unknown Source)
            at palidino76.rs2.util.SQLHandler.createConnection(SQLHandler.java:20)
            at palidino76.rs2.Engine.run(Engine.java:147)
            at java.lang.Thread.run(Unknown Source)my connection looks like this
         public static void createConnection() {
              try {
                        System.out.println("Creating connection to mysql server.");
                   String serverName = "sql306.phpnet.us:3306";
                   String mydatabase = "pn_2815767_java";
                   String url = "jdbc:mysql://" + serverName + "/" + mydatabase;
                   Class.forName("com.mysql.jdbc.Driver").newInstance();
                   con = DriverManager.getConnection(url, "pn_2815767", "password");
                   stmt = con.createStatement();
              } catch (Exception e) {
                   e.printStackTrace();
         }I'm messed up, if you know the problem please help.

    Use a connection pool and it will automatically take care of this for you (as long as you retreive the connection from the pool everytime you need it, and not just once at the start of the app, and close it as soon as you finish using it, not just at the "end" of the app, closing a pool connection simply returns it to the pool, it does not actually close it).
    Edit: That is, if the DB is part of the hosting service. If you are having the problem by the actual connection attempt, and the DB is located someplace else, then it is probably a routing/firewall issue. I.E. the hosting service is not allowing you to connect to it.

  • Possible to configure per connection timeout values?

    hi,
    please, does anybody know how (or whether or not it is even possible) to configure a "PER CONNECTION" timeout on the connections - created by jndi - to an ldap server?
    my understanding is that setting the "com.sun.jndi.ldap.connect.timeout" property on the javax.naming.directory.InitialDirContext sets a _global_ timeout value for _all_ connections created/managed by that InitialDirContext (that is, with a "PER CONTEXT" scope).
    however, what i would like to do instead, is somehow configure a different timeout value for each individual connection that a InitialDirContext might know about.
    the first solution that will probably pop in your head is "connection pool". however, the app sets "java.naming.ldap.factory.socket" property to a custom socket factory class. according to the following paragraph from the jndi tutorial, that disqualifies the app from using connection pools:
    "There are a couple of environment properties that automatically disqualify a Context instance from using a pooled connection. A Context instance cannot use a pooled connection if it has its "java.naming.ldap.factory.socket" property set to a custom socket factory class, or its "java.naming.security.sasl.callback" property set to a custom callback handler class, or its "com.sun.jndi.ldap.trace.ber" property set to enable protocol tracing."
    http://java.sun.com/products/jndi/tutorial/ldap/connect/config.html
    even if we could use connection pools, we still wouldn't be able to set "per connection" timeout values. would we?
    one proposed solution is to completely rip out jndi from the app and replace it with the netscape directory sdk for java. to me, that seems like too drastic a measure though - given the project's time-constraints (the way the app was originally designed does not lend itself to a straight-forward "pop-out/drop-in" type replacement). i was hoping there would be a simpler alternative (a jndi-based configuration type solution, for example).
    any suggestions would be gratefully appreciated. thanks in advance for your replies.

    Enable the Default Host option in the AirPort Admin Utility, use the IP address you have assigned to your server.

  • Connection timeout in web service calls

    Hi,
    We have a clustered weblogic 10gR3 environment where two nodes are for ILOG rule engine, two nodes for Oracle BPM engine and four nodes for Oracle BPM workspace. All the webserices calls are SOAP over HTTP. All the webservices to rule engine and DBAdapter are hosted on Oracle Service Bus. Some of the webservice calls when invoked throw a connection timeout exception. Can any one help on how to debug this or the possible causes for this scenario? The same webservice call when invoked or retried after a few minutes is working fine. Below is the stack trace:
    Stacktrace: java.net.ConnectException: Connection timed out: connect
         at java.net.PlainSocketImpl.socketConnect(Native Method)
         at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:333)
         at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:195)
         at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:182)
         at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
         at java.net.Socket.connect(Socket.java:519)
         at sun.reflect.GeneratedMethodAccessor212.invoke(Unknown Source)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:597)
         at org.apache.axis.components.net.DefaultSocketFactory.create(DefaultSocketFactory.java:153)
         at org.apache.axis.components.net.DefaultSocketFactory.create(DefaultSocketFactory.java:120)
         at org.apache.axis.transport.http.HTTPSender.getSocket(HTTPSender.java:191)
         at org.apache.axis.transport.http.HTTPSender.writeToSocket(HTTPSender.java:404)
         at org.apache.axis.transport.http.HTTPSender.invoke(HTTPSender.java:138)
         at org.apache.axis.strategies.InvocationStrategy.visit(InvocationStrategy.java:32)
         at org.apache.axis.SimpleChain.doVisiting(SimpleChain.java:118)
         at org.apache.axis.SimpleChain.invoke(SimpleChain.java:83)
         at org.apache.axis.client.AxisClient.invoke(AxisClient.java:165)
         at org.apache.axis.client.Call.invokeEngine(Call.java:2765)
         at org.apache.axis.client.Call.invoke(Call.java:2748)
         at org.apache.axis.client.Call.invoke(Call.java:2424)
         at org.apache.axis.client.Call.invoke(Call.java:2347)
         at org.apache.axis.client.Call.invoke(Call.java:1804)
         at fuego.soaptype.SoapCall.invoke(SoapCall.java:234)
         at fuego.soaptype.SoapObject.invoke(SoapObject.java:309)
         at fuego.lang.Invokeable.invokeImpl(Invokeable.java:234)
         at fuego.lang.Invokeable.invokeDynamic(Invokeable.java:188)
         at xobject.EDP.EDP.EDPObject.helpBusinessRules(EDPObject.xcdl:59)
         at oracle.EDPPROCESS.Default_6_6.Instance.CIL_checkRTDIInformation(Instance.xcdl:12)
         at oracle.EDPPROCESS.Default_6_6.Instance.CIL_checkRTDIInformation(Instance.xcdl)
         at sun.reflect.GeneratedMethodAccessor7653.invoke(Unknown Source)
         at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
         at java.lang.reflect.Method.invoke(Method.java:597)
         at fuego.server.execution.EngineExecutionContext.invokeMethodAsCil(EngineExecutionContext.java:1083)
         at fuego.server.execution.EngineExecutionContext.runCil(EngineExecutionContext.java:1278)
         at fuego.server.execution.microactivity.ComponentExecutionMicroActivity.runCil(ComponentExecutionMicroActivity.java:126)
         at fuego.server.execution.microactivity.ComponentExecutionMicroActivity.execute(ComponentExecutionMicroActivity.java:84)
         at fuego.server.execution.microactivity.MicroActivityEngineExecutionHandler.executeActivity(MicroActivityEngineExecutionHandler.java:57)
         at fuego.server.execution.ImmediateActivity.execute(ImmediateActivity.java:42)
         at fuego.server.execution.DefaultEngineExecution$AtomicExecutionTA.runTransaction(DefaultEngineExecution.java:304)
         at fuego.transaction.TransactionAction.startNestedTransaction(TransactionAction.java:527)
         at fuego.transaction.TransactionAction.startTransaction(TransactionAction.java:548)
         at fuego.transaction.TransactionAction.start(TransactionAction.java:212)
         at fuego.server.execution.DefaultEngineExecution.executeImmediate(DefaultEngineExecution.java:123)
         at fuego.server.execution.DefaultEngineExecution.executeAutomaticWork(DefaultEngineExecution.java:62)
         at fuego.server.execution.EngineExecution.executeAutomaticWork(EngineExecution.java:42)
         at fuego.server.execution.ToDoItem.executeAutomaticWork(ToDoItem.java:261)
         at fuego.ejbengine.ItemExecutionBean$1.execute(ItemExecutionBean.java:223)
         at fuego.server.execution.DefaultEngineExecution$AtomicExecutionTA.runTransaction(DefaultEngineExecution.java:304)
         at fuego.transaction.TransactionAction.startBaseTransaction(TransactionAction.java:470)
         at fuego.transaction.TransactionAction.startTransaction(TransactionAction.java:551)
         at fuego.transaction.TransactionAction.start(TransactionAction.java:212)
         at fuego.server.execution.DefaultEngineExecution.executeImmediate(DefaultEngineExecution.java:123)
         at fuego.server.execution.EngineExecution.executeImmediate(EngineExecution.java:66)
         at fuego.ejbengine.ItemExecutionBean.processMessage(ItemExecutionBean.java:209)
         at fuego.ejbengine.ItemExecutionBean.onMessage(ItemExecutionBean.java:120)
         at weblogic.ejb.container.internal.MDListener.execute(MDListener.java:466)
         at weblogic.ejb.container.internal.MDListener.transactionalOnMessage(MDListener.java:371)
         at weblogic.ejb.container.internal.MDListener.onMessage(MDListener.java:327)
         at weblogic.jms.client.JMSSession.onMessage(JMSSession.java:4547)
         at weblogic.jms.client.JMSSession.execute(JMSSession.java:4233)
         at weblogic.jms.client.JMSSession.executeMessage(JMSSession.java:3709)
         at weblogic.jms.client.JMSSession.access$000(JMSSession.java:114)
         at weblogic.jms.client.JMSSession$UseForRunnable.run(JMSSession.java:5058)
         at weblogic.work.SelfTuningWorkManagerImpl$WorkAdapterImpl.run(SelfTuningWorkManagerImpl.java:516)
         at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
         at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)

    EJP, thanks for confirming that the generated code is incorrect and that the finally block should be used.
    Jschell, thanks for the suggestions and the trust in my technical skills... though writing my own generator seems a bit of too great enterprise for me haha!
    The generator is not open source so I cannot modify it and using another one is not an option as it is the "standard" in the company.
    In the end I decided for writing a post processor (in the form of a JDeveloper extension) to fix the code after it is generated. I will also probably be filing a bug for it with Oracle.
    Cheers,
    Luis

  • Persistent socket connection - socket write error

    I'm connecting to a server using sockets. My application acts like a client, sending requests, and also like a server, listenning for notifications. I was using a client socket for the first task (send a message when required) and a server socket for the second (permanently listen for incoming messages). This needs to be some kind of persistent connection.
    It happens now I'm required to send and receive using the same port. The only way I found to do this is to have a single socket (client) bound to a certain port. It connects to the server and one thread keeps listenning for incoming messages (by reading the input stream) while another process is launched whenever I need to send a message (by writing to the socket's output stream). The socket is created only once (when the application starts) and its output/input streams reused whenever needed.
    This works well for a while. However, when I try to send a message after some idle time (lets say 20 minutes) strange things happen. The first attempt to send a message returns success (although nothing is actually received by the server). The second attempt returns java.net.SocketException: Software caused connection abort: socket write error. I don't understand this behaviour. Can there be a timeout? I only write to the socket after testing if it's connected.. So why is this failing? Also, any other ideas on how to send and receive using the same port? A different and better approach maybe..
    Thanks in advance

    Socket.isConnected just tells you whether you have personally called Socket.connect() or new Socket(host, port,...). It doesn't tell you anything about the state of the connection.
    You should certainly issue periodic application 'pings' at suitable intervals, and many application protocols do this. For example, Java RMI reuses connections that are less than 15 seconds old but only if they pass a ping test.
    In general however you can't insist on a persistent connection over TCP/IP, especially if you have this kind of hardware in the circuit. What you can do is recognize when the connection has been lost and form a new one. The network is going to fail somewhere some time and your program has to be robust against that.

  • Using thread and socket connection with other machines

    Hi all!
    we are using weblgoic 5.1 SP9 JDK1.2.2
    we already using java.net.Socket and java.lang.Thread
    to communication TANDEM Machine on the weblogic.
    the reason why we use to socket and thread even though it is not
    recommanded is that below
    1. once we connect Socket, then we using until server shutdown or
    connection may has the problem, so we're using thread to wait
    java.io.Inputstream to read from socket.(if I using EJB, It can't
    wait socket inputstream indefinetly, because it has timeout)
    2. we're logging Database date sent or received with TANDEM Machine.
    so we need Database Access. so we using Database Access
    thru Weblogic.
    3. EJB Application using (other EJB Application - send Module)
    to send data to TANDEM Machine. So "Send Module" should
    be implemented EJB.
    but. Now I see there might be problem this framework.
    so, is there some way by just using J2EE spec, to implement this kind of
    framework.
    wait for your great help !!
    regards.

    Yes i've tried interrupt method and it doesn't have any effects on the thread... it stay in connect() method...
    And for the timeouts, in fact i use an API : J2SSH, to connect with SSH protocol, and the setting of connection timeouts is not implemented yet... and the default timeout is about 4 minutes...
    so i don't know how to solve this problem...

Maybe you are looking for