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.

Similar Messages

  • 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?

  • How to make SAP B1 connection with Windows Sharepoint Service 3.0

    how to make SAP B1 connection with Windows Sharepoint Service 3.0 through asp.net web part code.. I get the security error when i run that web part......
    public bool ConnectToCompany()
                oCompany = new SAPbobsCOM.Company();
                oCompany.Server = "192.168.1.58";
                oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2005;
                oCompany.CompanyDB = "SBODemoUS";
                oCompany.DbUserName = "sa";
                oCompany.DbPassword = "abc";
                //oCompany.UseTrusted = true;
                oCompany.UserName = "manager";
                oCompany.Password = "manager";
                oCompany.language = SAPbobsCOM.BoSuppLangs.ln_English;
                oCompany.LicenseServer = "192.168.1.58:30000";
                int i = oCompany.Connect();
                if (i != 0)
                    return false;
                return true;
    protected override void RenderContents(HtmlTextWriter writer)
                if (conn.ConnectToCompany() == true)
                    writer.Write("Hello" + this.Context.User.Identity.Name);
    Edited by: bikalg on Nov 28, 2010 9:43 AM

    Hi.......
    Welcome to SAP Business One Forum.....
    Unfortunately this is the wrong forum you posted here.
    I would suggest you post it in SDK or System Administration Forum and definitely you get the solution and close this thread from here......
    Regards,
    Rahul

  • How to make the wifi connection with Ipad in china since it requires user's name and password.

    How to make the wifi connection with Ipad in china since it requires user's name and password just like the dialed-up?

    The same way you would connect to a secure wifi network in any other country. Supply the username and password when prompted.

  • Is there any way to make a socket connection to a java file on the net?

    Is their anyway to make a socket connection to a java applet that I place on a webhost? I want to connect to a javaapplet from my vb.net program and send commands to it. Like http://www.geocities.com/Sylonious/javafile.jpx:7070
    ?

    Is their anyway to make a socket connection to a java
    applet that I place on a webhost? I want to connect to
    a javaapplet from my vb.net program and send commands
    to it. Like
    http://www.geocities.com/Sylonious/javafile.jpx:7070
    ?You wouldn't have a port in the url, you would need to have the socket open in the applet code. The vb.net program would also need to be on the same server as the applet or you'll have security issues and I doubt that's possible with geocities. I don't know what you would need to communicate with a vb.net if anything, but I'm sure it's possible.

  • How to make VPN client auto timeout when it still idle?

    How to make VPN client auto disconnect when it still idle?
    Hi,I found some user still connected the VPN evenif they dose not use the VPN resouse.
    I try to set a "idle timeout" for the VPN configuration.
    We use PIX515 8.0.3 and CISCO ACS 4.2 for the VPN's connection and authentication,and the user use cisco vpn client for the connection.
    I have tried many methods,but all failured.
    First,I configed "vpn-idel-timeout 5" on PIX.It can not worked.
    so,I add Radius(CISCO VPN 3000/ASA/PIX 7.0+) attribute "[026/3076/050] Authenticated-User-Idle-Timeout" on CISCO ACS,It still not worked.
    And I also add IETF RADIUS Attributes "[028] Idle-Timeout" on group setting on ACS,it always not worked.
    i found in vpn client's statistics,it always has some byte sended or received, i thought it maybe IPsec keepalive message or Radius message.
    This maybe the reason because the PIX or ACS think the vpn user is keep working.
    Can someone tell me how to make a "idle time out"?
    best regard.
    Roger

      here is the configuration on PIX,
    group-policy DfltGrpPolicy attributes
    wins-server value 10.0.0.67 10.0.0.68
    dns-server value 10.0.0.67 10.0.0.68
    vpn-simultaneous-logins 20
    vpn-idle-timeout 5
    split-tunnel-policy tunnelspecified
    split-tunnel-network-list value vpn-acl
    default-domain value mydomain.com
    address-pools value vpnpool group-policy DfltGrpPolicy attributes
    wins-server value 10.0.0.67 10.0.0.68
    dns-server value 10.0.0.67 10.0.0.68
    vpn-simultaneous-logins 20
    vpn-idle-timeout 5
    split-tunnel-policy tunnelspecified
    split-tunnel-network-list value vpn-acl
    default-domain value want-want.com
    address-pools value vpnpool

  • How to make the client connect to the server at the command prompt?

    I found this code on IBM's website, it was a training session on servers and clients using java.
    The code compiles fine and the server seems to start up properly when I use java Server 5000. I think whats happening is the server is running and listening for a connection on port 5000.
    When I try to run the client I get the following error.
    Exception in thread "main" java.lang.NoSuchMethodError: main
    I see a start() method but no main. As far as I know, applications should all have main, it seems as if the person who wrote this kinda confused applets with application. Not that I would really know what happened.
    If you have time, could you tell me if there's an easy fix for this? I would love to have this client/server working if it isn't too much trouble. As I have looked all over the net for a free client/server applet that will actually let me see the java code and none of the free ones do allow getting to their source.
    Most of them allow you to customize them somewhat but also have built in advertising that can't be removed.
    This is the closest I have come to finding one that lets me look under the hood. But alas it doesn't work out of the box and I don't know what to do to fix it.
    Heres the code: Server:
    import java.io.*;
    import java.net.*;
    import java.util.*;
    public class Server
      // The ServerSocket we'll use for accepting new connections
      private ServerSocket ss;
      // A mapping from sockets to DataOutputStreams.  This will
      // help us avoid having to create a DataOutputStream each time
      // we want to write to a stream.
      private Hashtable outputStreams = new Hashtable();
      // Constructor and while-accept loop all in one.
      public Server( int port ) throws IOException {
        // All we have to do is listen
        listen( port );
      private void listen( int port ) throws IOException {
        // Create the ServerSocket
        ss = new ServerSocket( port );
        // Tell the world we're ready to go
        System.out.println( "Listening on "+ss );
        // Keep accepting connections forever
        while (true) {
          // Grab the next incoming connection
          Socket s = ss.accept();
          // Tell the world we've got it
          System.out.println( "Connection from "+s );
          // Create a DataOutputStream for writing data to the
          // other side
          DataOutputStream dout = new DataOutputStream( s.getOutputStream() );
          // Save this stream so we don't need to make it again
          outputStreams.put( s, dout );
          // Create a new thread for this connection, and then forget
          // about it
          new ServerThread( this, s );
      // Get an enumeration of all the OutputStreams, one for each client
      // connected to us
      Enumeration getOutputStreams() {
        return outputStreams.elements();
      // Send a message to all clients (utility routine)
      void sendToAll( String message ) {
        // We synchronize on this because another thread might be
        // calling removeConnection() and this would screw us up
        // as we tried to walk through the list
        synchronized( outputStreams ) {
          // For each client ...
          for (Enumeration e = getOutputStreams(); e.hasMoreElements(); ) {
            // ... get the output stream ...
            DataOutputStream dout = (DataOutputStream)e.nextElement();
            // ... and send the message
            try {
              dout.writeUTF( message );
            } catch( IOException ie ) { System.out.println( ie ); }
      // Remove a socket, and it's corresponding output stream, from our
      // list.  This is usually called by a connection thread that has
      // discovered that the connectin to the client is dead.
      void removeConnection( Socket s ) {
        // Synchronize so we don't mess up sendToAll() while it walks
        // down the list of all output streamsa
        synchronized( outputStreams ) {
          // Tell the world
          System.out.println( "Removing connection to "+s );
          // Remove it from our hashtable/list
          outputStreams.remove( s );
          // Make sure it's closed
          try {
            s.close();
          } catch( IOException ie ) {
            System.out.println( "Error closing "+s );
            ie.printStackTrace();
      // Main routine
      // Usage: java Server <port>
      static public void main( String args[] ) throws Exception {
        // Get the port # from the command line
        int port = Integer.parseInt( args[0] );
        // Create a Server object, which will automatically begin
        // accepting connections.
        new Server( port );
    }CLIENT:
    import java.io.*;
    import java.net.*;
    public class ServerThread extends Thread
      // The Server that spawned us
      private Server server;
      // The Socket connected to our client
      private Socket socket;
      // Constructor.
      public ServerThread( Server server, Socket socket ) {
        // Save the parameters
        this.server = server;
        this.socket = socket;
        // Start up the thread
        start();
      // This runs in a separate thread when start() is called in the
      // constructor.
      public void run() {
        try {
          // Create a DataInputStream for communication; the client
          // is using a DataOutputStream to write to us
          DataInputStream din = new DataInputStream( socket.getInputStream() );
          // Over and over, forever ...
          while (true) {
            // ... read the next message ...
            String message = din.readUTF();
            // ... tell the world ...
            System.out.println( "Sending "+message );
            // ... and have the server send it to all clients
            server.sendToAll( message );
        } catch( EOFException ie ) {
          // This doesn't need an error message
        } catch( IOException ie ) {
          // This does; tell the world!
          ie.printStackTrace();
        } finally {
          // The connection is closed for one reason or another,
          // so have the server dealing with it
          server.removeConnection( socket );
    }Thanks for your time.

    CLIENT:
    import java.applet.*;
    import java.awt.*;
    import java.awt.event.*;
    import java.io.*;
    import java.net.*;
    public class Client extends Panel implements Runnable
      // Components for the visual display of the chat windows
      private TextField tf = new TextField();
      private TextArea ta = new TextArea();
      // The socket connecting us to the server
      private Socket socket;
      // The streams we communicate to the server; these come
      // from the socket
      private DataOutputStream dout;
      private DataInputStream din;
      // Constructor
      public Client( String host, int port ) {
        // Set up the screen
        setLayout( new BorderLayout() );
        add( "North", tf );
        add( "Center", ta );
        // We want to receive messages when someone types a line
        // and hits return, using an anonymous class as
        // a callback
        tf.addActionListener( new ActionListener() {
          public void actionPerformed( ActionEvent e ) {
            processMessage( e.getActionCommand() );
        // Connect to the server
        try {
          // Initiate the connection
          socket = new Socket( host, port );
          // We got a connection!  Tell the world
          System.out.println( "connected to "+socket );
          // Let's grab the streams and create DataInput/Output streams
          // from them
          din = new DataInputStream( socket.getInputStream() );
          dout = new DataOutputStream( socket.getOutputStream() );
          // Start a background thread for receiving messages
          new Thread( this ).start();
        } catch( IOException ie ) { System.out.println( ie ); }
      // Gets called when the user types something
      private void processMessage( String message ) {
        try {
          // Send it to the server
          dout.writeUTF( message );
          // Clear out text input field
          tf.setText( "" );
        } catch( IOException ie ) { System.out.println( ie ); }
      // Background thread runs this: show messages from other window
      public void run() {
        try {
          // Receive messages one-by-one, forever
          while (true) {
            // Get the next message
            String message = din.readUTF();
            // Print it to our text window
            ta.append( message+"\n" );
        } catch( IOException ie ) { System.out.println( ie ); }
    import java.applet.*;
    import java.awt.*;
    import java.io.*;
    import java.net.*;
    public class ClientApplet extends Applet
      public void init() {
        String host = getParameter( "192.168.1.47" );
        int port = Integer.parseInt( getParameter( "5000" ) );
        setLayout( new BorderLayout() );
        add( "Center", new Client( host, port ) );
    }Sorry about that. Now when I run an html file with this applet I just get the x in the corner.
    Thanks for looking.

  • 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.

  • How to make common database connection using bean, etc.

    anyone know how to make a coomon database connection because on my web pages each of them need to connect on the database for their specific objectives... please help
    regards
    blingbling
    Edited by: BlingBling15 on Oct 22, 2007 1:16 PM

    Making a 'common' connection and passing it around is a bad idea. And making a new connection on every page, as you seem to have already guessed, also involves an overhead that you can do without.
    Like drvijayj2k2 has mentioned, you should use connection pooling.
    Take a look at the Apache Commons DBCP [1] and it's examples [2].
    [1] http://commons.apache.org/dbcp/
    [2] http://wiki.apache.org/jakarta-commons/DBCP
    People on the forum help others voluntarily, it's not their job.
    Help them help you.
    Learn how to ask questions first: http://faq.javaranch.com/java/HowToAskQuestionsOnJavaRanch
    ----------------------------------------------------------------

  • How to make new database connection using Oracle BI Interactive Dashboards

    Hi,
    I install Oracle BI Intelligence on my system.
    I am using Oracle BI Interactive Dashboard. Here we have default database connection.
    but now i want to use it for my own database. Can any body give me guideline how to
    make a new data base connection using this s/w or how to connect to my database so
    that i can make my own reports.
    I am using
    http://www.oracle.com/technology/obe/obe_bi/bi_ee_1013/saw/saw.html
    this link.
    i make odbc connection which is fine.
    but
    Restoring the Business Intelligence Presentation Catalog and Updating Metadata
    The third point blow above heading is not clear.
    Thanks

    Umesh - in order to build Answers and Dashboard content you must first setup a Physical model, then a Business model, followed by a Presentation Catalog/Subject Area.
    All these tasks are carried out using the Repository Administration Utility.
    1) Import your physical tables using OCI/ODBC into the physical layer.
    2) Build your model
    3) Deploy
    Then you're ready to start building answers/dashboards.
    Good Luck.

  • TP4 How to make an AppServer connection through a Firewall ?

    In the Resource Manager we can not seem to find a way to modify the url to include http: ... Can someone point out some document on how to do this?

    Chris Thanks for your reply. I am trying to do the following:
    In the "application server navigator" under application servers I am attempting to make a connection to a JDev TP4 instance in stand alone mode that is behind a fire wall.
    My understanding from the OC4J docs is have seen is I need to use a http port but in the connection manager I do not see a way to adapt the url to make a proper connection. Is this something that was just not taken into account ??? or am I just missing something here to make the connection. The help is of no use on this subject so I appreciate any assistance I can get.

  • How to make a internet connection!!

    I need to make a internet connection before a start a servlet (client) there's a form to do that ????

    There is no such thing as a 'internet connection'. You don't connect to the internet, you connect to computers - like DSN servers, web servers etc.
    Presumably you have a network. A client (browser) must connect to an application server to use a servlet. This is true even when running on the same box.
    Your question is how to you connect to the web server? What application/web server are you running?

  • How to make a program for backgroung processing used servlet

    how to make a program for backgroung processing used servlet

    well i need the coding part written in servlet ,in which servlet is always ready for accepting a client request.

  • How to make my Ipad connect to app store

    My Ipad will not connect to the app store . how can I make it connect

    1. Make sure iPad is using the latest software
    2. Settings>General>Date and Time>Set Automatically>On
    3. Make sure Time Zone is correct
    4. Reset iPad. Hold the Sleep and Home button down until you see the Apple Logo.

  • How To make/configure  Broadband connection in Sun java desktop system

    Hi all,
    I am using sun java desktop system Release 3 solaris 10 version in my sun ultra workstation. I have a problem with it. I can not make broadband connection , in it. so pls let me know how can i make broadband connection with my ADSL modem ?
    Thanks
    Partha

    Try this:
    Log into a termina as rootl. (Select failsafe terminal or command login)
    To get the name of your network interface driver, type:
    /usr/sbin/ifconfig -a You'll see something like this:
    lo0: flags=2001000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4,VIRTUAL> mtu 8232 index 1
    inet 127.0.0.1 netmask ff000000
    hme0: flags=1000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4> mtu 1500 index 2
    inet 129.156.226.245 netmask ffffff00 broadcast 129.156.226.255
    In my case it is hme0 so I create a file called /etc/dhcp.hme0:
    touch /etc/dhcp.hme0If you want to set a hostname, put it in a file called /etc/hostname.hme0 for example:
    rm /etc/hostname.hme0
    echo myhostname > /etc/hostname.hme0Most broadband providers preconfigure ADSL modems to default to DHCP so if you do this, connect the ultra 10 to the broadband modem and reboot, the ultra 10 should pick up an IP address and be connected to the internet.

Maybe you are looking for

  • STO Issue,Intra company

    Hi, We have created one document for plant to plant STO within same company code.Here we have two separate profit center for two plant.When I will do PGI inventory account entry is generated  and value is moving from one profit center to another but

  • How to remove Java Applications from "Add and Remove Programs" list?

    I have deployed my Java applications (both JWS and Applet) via JNLP with allow-offline option enabled and without installer-desc option specified. My questions are: 1. An entry is added to the Add and Remove Programs list after launching the applicat

  • Adobe acrobat RDS Requirements

    Dear All, We have a slow printing issues with Adobe Acrobat on a RDS Windows 2012R2 Infrastructure. Can anyone tell me if Adobe Acrobat Standard XI is supported by Acrobat on Windows 2012R2 RDS. I cannot find any specific requirements required for Wi

  • Grant fails...

    hello all, i am on 10.2.0.4, when i try to give the below grant i get following error... Grant execute on sys_context to user; ORA-04042: procedure, function, package, or package body does not exist wat am i missing here...i couldnt find anything use

  • String str = " Select ? , ...

    Hi , I have a query for which I need to use PreparedStatement .The query runs likes this :- String str = " Select ? , ename from emp where deptno ? "; The values of ? need to be assigned dynamically. But I cannot create Prepared Statement from this q