Socket connect slow in JDK 1.5?

We recently began testing our Java Swing application with JDK 1.5, and we noticed that socket.connect()
calls are taking several seconds to return, when before in 1.4 the calls returned immediately.
Here is some sample code:
Socket sock = new Socket();
InetSocketAddress sockAddr = new InetSocketAddress(inAddress, portNum);
sock.connect(sockAddr, 2000);
What could be wrong? I've debugged the code and verified inAddress is an IP address,
not a hostname.
-Eric

Here is the list of enhancements in JDK1.5.
http://java.sun.com/j2se/1.5.0/docs/guide/net/enhancements-1.5.0.html
I wonder if any of them are having some effect in the slow connection.
There are some network properties that you can tweak with. Did you try them?
Here is the list
http://java.sun.com/j2se/1.5.0/docs/guide/net/properties.html

Similar Messages

  • Socket connecting slow?

    I'm new to Java network programming, and I need a sanity-check on
    something. I have two Windows XP machines connected via TCP/IP,
    100-base-T, and I constructed a "server" app on one which makes a
    new ServerSocket, then a Socket from that with .accept (), then an
    OutputStream with .getOutputStream (), with a PrintWriter wrapping
    that, via which I then "serve" some data with .println ().
    On the other, I built a "client" app, which makes an InputStream on a
    new Socket with .getInputStream (), and then retrieves those "served"
    lines with a BufferedReader wrapping an InputStreamReader for that
    Socket.
    When I run the client and server on the same machine, it connects
    pretty much instantaneously, but when they are separated by that
    100-base-T cable, it literally takes 2 seconds for the connection to
    be made (not JVM startup time). It takes literally 10 seconds if I use
    a "security manager". A "ping" between the machines is "< 1ms".
    These times are with no firewalls. And I'm running from command
    lines.
    Is a 2 second connect time usual? Is it avoidable? Is this a
    Windows problem?
    - Lenny Gray -

    Okay, here's the code. It's hardly more than what I described.
    I don't quite get how to post code neatly here. And the 2 seconds
    I'm talking are from when the client requests the socket connection,
    to when the server's "accept" returns. Everything else seems to
    go quickly enough.
    import java.io.*;
    import java.net.*;
    public class Client
    {public static void main (String [] args)
    {  System.out.println ("starting...");
    try
    {Socket  s = new Socket ("169.254.249.188", 1234);
    System.out.println ("Socket returned");
    InputStream    is = s .getInputStream ();
        System.out.println ("getInputStream ret'd");
    InputStreamReader    isr = new InputStreamReader (is);
    BufferedReader     br = new BufferedReader (isr);
        System.out.println ("BufferedReader ret'd");
    int i;    for ( i=0; i<10; i++ )
    {    System.out.println (br .readLine ());
    } s .close ();
    } catch (IOException e)
    {    System.out.println ("IOExceoption");
    import java.io.*;
    import java.net.*;
    public class Server
    {public static void main (String [] args)
    {  try
    {ServerSocket     ss = new ServerSocket (1234);
        while (true)
    {Socket      s = ss .accept ();  // wait for connect
        System.out.println ("accept returned");
    OutputStream      o = s .getOutputStream ();
    PrintWriter          p = new PrintWriter (o, true);
    int i;      for ( i=1;  i <= 10;  ++i )
          p .println ("This is a line " + i);
          p .close ();
          s .close ();
    }} catch (IOException e)
    {      System.out.println ("IOException");
    }}}

  • Establishing Socket Connection to a slow or busy server

    Currently, I'm developing an AIM-based BOT application in Java and it requires establishing a socket connection to their free and public server (host: toc.oscar.aol.com, port: 9898).
    About 75% of the time a connection will be successfully established using this:
    oConnection = new Socket("toc.oscar.aol.com", 9898);
    25% of the time when a connection fails (timeout) is due to the server being too slow or busy to respond to the connection request; however, the server will eventually response within 40 to 60 seconds.
    Let me go into details with my findings when attempting to connect to the slow/busy server:
    For experimental purposes, I used the telnet command (via the DOS command prompt: "telnet toc.oscar.aol.com 9898"), the connection will be established usually within 40 to 60 seconds.
    As I said before, the BOT application is developed in a Java environment and when attempting to establish a connection (using Java's Socket), a timeout exception gets raised when it hits the 20-seconds mark. It tells me that the Java Socket has the timeout defaulted to 20-seconds.
    I am aware that we can define the timeout settings using Socket's "setSoTimeout(x)" method; however, it's only good for AFTER a connection is established.
    Now, to sum up my findings � it clearly shows that the DOS' telnet prompt has longer "wait time" before raising any exceptions. As far as Java Socket is concerned, if a connection is not established within 20 seconds, it raises the timeout exception.
    Is there a way to stretch the "wait time" or "timeout" to be longer than 20 seconds for when a socket connection is being attempted?
    Millions of thanks in advance,
    Chad W. Taylor

    Yes, I also tried that option but no cigar. That
    timeout value is an alternative way of using
    setSoTimeout(int).
    I don't think so.
    First the Java documentation would not make sense:
    public void connect(SocketAddress endpoint, int timeout)
    throws IOException
    Connects this socket to the server with a specified timeout value. A timeout of zero is interpreted as an infinite timeout. The connection will then block until established or an error occurs.
    Parameters:
    endpoint - the SocketAddress
    timeout - the timeout value to be used in milliseconds.
    Throws:
    IOException - if an error occurs during the connection
    SocketTimeoutException - if timeout expires before connecting
    IllegalBlockingModeException - if this socket has an associated channel, and the channel is in non-blocking mode
    IllegalArgumentException - if endpoint is null or is a SocketAddress subclass not supported by this socket
    Since: 1.4
    Second my tests indicate otherwise:
    public class Main {
    public static void main(String[] args) {
    try {
         Socket conn = new Socket();
         conn.connect(new InetSocketAddress(InetAddress.getByName("toc.oscar.aol.com"),9898), Integer.parseInt(args[0]));
         System.out.println("connected under " + args[0] + " seconds");
         conn.close();
    } catch (Exception e) {
         System.out.println("not connected in " + args[0] + " seconds");
         e.printStackTrace();
    Different runs show:
    connected under 120 seconds
    and
    not connected in 20 seconds
    java.net.SocketTimeoutException: connect timed out
         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.Socket.connect(Unknown Source)
         at Main.main(Main.java:21)
    I speculate that the "Connection Request Timeout"
    value is platform dependent because when I use a
    different machine, the request timeout is either
    longer or shorter than 20 seconds.
    That could well be the case.
    So the proper question would be -- where is the Java
    Socket borrowing the timeout value from? The settings
    in Winsock?
    That I don't know.
    Andreas
    Chad

  • 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

  • Socket Connecting

    I create the SocketServer but then my program just stand there and will not allow me to start up my Client. If I try to run the ServerSocket program again, it catches my IOException. Is there something wrong with my connection?

    What is a SocketServer? and what do you mean by 'my IOException'?
    Be precise: nobody here is a mind reader.
    If you mean ServerSocket, there is a lot more to it than just executing new ServerSocket(). See the Sockets tutorial in the JDK documentation.

  • Java Socket Connection Time out

    Goal*
    I want to check host/port availability of computers in our network (~100 computers) .. Just check if host is alive and if it has port 445 opened. I want to do this somehow in parallel, so the code execution is as quick as possible.
    My implementation*
    I do this by creating socket connection to the host. Something like this:
            Socket s = null;
            try {
                s = new Socket();
                InetSocketAddress socketAddress = new InetSocketAddress(ipAddress, 445);
                s.connect(socketAddress, 3000);
                if (s.isConnected()) {
                    // do something
            } catch (ConnectException ex) {
                //exception thrown
            } catch (IOException ex1) {
                //exception thrown
            } finally {
                try {
                    // close socket
                    s.close();
                } catch (IOException ex) {
                    Logger.getLogger(ComputerModel.class.getName()).log(Level.SEVERE, null, ex);
            }This code is executed in a loop, where a separate thread is created for every iteration = ~100 separate threads.
    Problem:*
    1.
    It seems to me, that first ~10-15 connections are created ok, but then my code reaches 'IOException' catch block for every subsequent itteration and ex.getMessage() returns "connection time out" (I try to use different timeout values in the 2nd parameter. Values from 3000 up to 20000).
    Is it valid to create 100 separate threads in a loop? Can't I make my NIC to bussy with this ??? What is the maximum ammount of threads, I can create? I did not use threads before, so I have no idea, if max values are near to 10, 100, 1000, or 10000 ..
    2.
    After my code is executed, I enter 'netstat -an' command in my command line and I get bunch of connections, which report status of SYN_SENT for several connections.
    TCP 10.20.11.140:4557 10.30.11.119:445 SYN_SENT
    TCP 10.20.11.140:4558 10.30.11.176:445 SYN_SENT
    TCP 10.20.11.140:4559 10.30.11.100:445 SYN_SENT
    TCP 10.20.11.140:4560 10.30.11.142:445 SYN_SENT
    TCP 10.20.11.140:4561 10.30.11.171:445 SYN_SENT
    TCP 10.20.11.140:4562 10.30.11.143:445 SYN_SENT
    TCP 10.20.11.140:4563 10.30.12.12:445 SYN_SENT
    TCP 10.20.11.140:4564 10.30.12.11:445 SYN_SENT
    TCP 10.20.11.140:4565 10.30.12.21:445 SYN_SENT
    TCP 10.20.11.140:4566 10.30.11.150:445 SYN_SENT
    I also feel, that my computer network response (e.g. firefox browsing) is a bit slower ..
    How shall I handle this problem properly?
    Thx in advance,
    Juraj

    kajbj wrote:
    tschodt wrote:
    kajbj wrote:
    The documentation for netstat explains what SYN_SENT is, but
    I don't know why you have them.The app has asked the TCP stack to transmit SYN
    the TCP stack is now waiting for SYN-ACK.
    If there is no host at that IP address or a host that drops connections (SYN packets) for TCP port 445
    there will never be a SYN-ACK.
    After a few minutes the TCP stack will time out the connection attempt.Yes, I was rather commenting on why his hosts aren't answering. I thought that his case was that all of them should answer :)Akkurat. I was answering more for clarification.
    Someone who does not know your posting history could easily assume you meant
    it was a mystery why netstat was showing SYN_SENT.
    And I figured it would not harm to hint that one possible reason would be that those machines are powered off (no host).

  • Is there any way to identify the particular socket connection is closed ?

    Is there any way to identify the particular socket connection is closed or not ?
    Any methods ???
    How can the program knows the connection is lost or some thing ...
    Is the socket throws some excpetions when there is no active connection ???
    namanc

    If you get an IOException when you try to use the socket, the connection was obviously closed.
    The correct way for an application to know if the socket was closed is:
    1) the server sends a message indicating that the socket should be closed
    2) the client closes the socket itself

  • I suppose it is the problem with socket connection,Please help

    Hi,
    I'm trying to build a chat server in Java on Linux OS.I've created basically 2 classes in the client program.The first one shows the login window.When we enter the Login ID & password & click on the ok button,the data is sent to the server for verification.If the login is true,the second class is invoked,which displays the messenger window.This class again access the server
    for collecting the IDs of the online persons.But this statement which reads from the server causes an exception in the program.If we invoke the second class independently(ie not from 1st class) then there is no problem & the required data is read from the server.Can anyone please help me in getting this program right.I'm working on a p4 machine with JDK1.4.
    The Exceptions caused are given below
    java.net.SocketException: Connection reset by peer: Connection reset by peer
    at java.net.SocketInputStream.SocketRead0(Native Method)
    at java.net.SocketInputStream.read(SocketInputStream.java:119)
         at java.io.InputStreamReader$CharsetFiller.readBytes(InputStreanReader.java :339)
         at java.io.InputStreamReader$CharsetFiller.fill(InputStreamReader.java:374)
         at java.io.InputStreamReader.read(InputStreamReader.java:511)
         at java.io.BufferedReader.fill(BufferedReader.java:139)
         at java.io.BufferedReader.readLine(BufferedReader.java:299)
         at java.io.BufferedReader.readLine(BufferedReader.java:362)
         at Login.LoginData(Login.java:330)
         at Login.test(Login.java:155)
         at Login$Buttonhandler.actionPerformed(Login.java:138)
         at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1722)
         at javax.swing.AbstractButton$ForwardActionEvents.actionPerformed(AbstractButton.java:17775)
         at javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:4141)
         at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:253)
         at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:261)
         at java.awt.Component.processMouseEvent(Component.java:4906)
         at java.awt.Component.processEvent(component.java:4732)
         at java.awt.Container.processEvent(Container.java:1337)
         at java.awt.component.dispatchEventImpl(Component.java:3476)
         at java.awt.Container.dispatchEventImpl(Container.java:1399)
         at java.awt.Component.dispatchEvent(Component.java:3343)
         at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:3302)
         at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3014)
         at java.awt.LightweightDispatcher.dispatchEvent(Container.java:2967)
         at java.awt.Container.dispatchEventImpl(Container.java:1373)
         at java.awt.window.dispatchEventImpl(Window.java:1459)
         at java.awt.Component.dispatchEvent(Component.java:3343)
         at java.awt.EventQueue.dispatchEvent(EventQueue.java:439)
         at java.awt.EventDispatchThread.pumpOneEvent(EventDispatchThread.java:150)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:136)
         at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:131)
         at java.awt.EventDispatchThread.run(EventDispatchThread.java:99)
         My program looks somewhat like this :
    1st class definition:
    public class Login extends Jframe// Login is the name of the first class;
    Socket connection;
    DataOutputStream outStream;
    BufferedReader inStream;
    Frame is set up here
    public class Buttonhandler implements ActionListener
    public void actionPerformed(ActionEvent e) {
    String comm = e.getActionCommand();
    if(comm.equals("ok")) {
    check=LoginCheck(ID,paswd);
    test();
    public void test() //checks whether the login is true
    if(check)
    new Messenger(ID);// the second class is invoked
    public boolean LoginCheck(String user,String passwd)
    //Enter the Server's IP & port below
    String destination="localhost";
    int port=1234;
    try
    connection=new Socket(destination,port);
    }catch (UnknownHostException ex){
    error("Unknown host");
    catch (IOException ex){
    ex.printStackTrace ();
    error("IO error creating socket ");
    try{
    inStream = new BufferedReader(new InputStreamReader(connection.getInputStream()));
    outStream=new DataOutputStream(connection.getOutputStream());
    }catch (IOException ex){
    error("IO error getting streams");
    ex.printStackTrace();
    System.out.println("connected to "+destination+" at port "+port+".");
    BufferedReader keyboardInput=new BufferedReader(new InputStreamReader(System.in));
    String receive=new String();
    try{
    receive=inStream.readLine();
    }catch(IOException ex){ error("Error reading from server");}
    if(receive.equals("Logintrue"))
    check=true;
    else
    check=false;
    try{
    inStream.close();
    outStream.close();
    connection.close();
    }catch (IOException ex){
    error("IO error closing socket");
    return(check);
    // second class is defined below
    public class Messenger
    Socket connect;
    DataOutputStream outStr;
    BufferedReader inStr;
    public static void main(String args[])
    { Messenger mes = new Messenger(args[0]);}
    Messenger(String strg)
    CreateWindow();
    setupEvents();
    LoginData(strg);
    fram.show();
    void setupEvents()
    fram.addWindowListener(new WindowHandler());
    login.addActionListener(new MenuItemHandler());
    quit.addActionListener(new MenuItemHandler());
    button.addActionListener(new Buttonhandle());
    public void LoginData(String name)
    //Enter the Server's IP & port below
    String dest="localhost";
    int port=1234;
    int r=0;
    String str[]=new String[40];
    try
    connect=new Socket(dest,port);
    }catch (UnknownHostException ex){
    error("Unknown host");
    catch (IOException ex){
    ex.printStackTrace ();
    error("IO error creating socket ");
    try{
    inStr = new BufferedReader(new InputStreamReader(connect.getInputStream()));
    outStr=new DataOutputStream(connect.getOutputStream());
    }catch (IOException ex){
    error("IO error getting streams");
    ex.printStackTrace();
    String codeln=new String("\n");
    try{
    outStr.flush();
    outStr.writeBytes("!@*&!@#$%^");//code for sending logged in users
    outStr.writeBytes(codeln);
    outStr.write(13);
    outStr.flush();
    String check="qkpltx";
    String receive=new String();
    try{
    while((receive=inStr.readLine())!=null) //the statement that causes the exception
    if(receive.equals(check))
    break;
    else
         str[r]=receive;
         r++;
    }catch(IOException ex){ex.printStackTrace();error("Error reading from socket");}
    catch(NullPointerException ex){ex.printStackTrace();}
    } catch (IOException ex){ex.printStackTrace();
    error("Error reading from keyboard or socket ");
    try{
    inStr.close();
    outStr.close();
    connect.close();
    }catch (IOException ex){
    error("IO error closing socket");
    for(int l=0,k=1;l<r;l=l+2,k++)
    if(!(str[l].equals(name)))
    stud[k]=" "+str[l];
    else
    k--;
    public class Buttonhandle implements ActionListener
    public void actionPerformed(ActionEvent e) {
    //chat with the selected user;
    public class MenuItemHandler implements ActionListener
    public void actionPerformed(ActionEvent e)
    String cmd=e.getActionCommand();
    if(cmd.equals("Disconnect"))
    //Disconnect from the server
    else if(cmd.equals("Change User"))
         //Disconnect from the server & call the login window
    else if(cmd.equals("View Connection Details"))
    //show connection details;
    public class WindowHandler extends WindowAdapter
    public void windowClosing(WindowEvent e){
    //Disconnect from server & then exit;
    System.exit(0);}
    I�ll be very thankful if anyone corrects the mistake for me.Please help.

    You're connecting to the server twice. After you've successfully logged in, pass the Socket to the Messenger class.
    public class Messenger {
        Socket connect;
        public static void main(String args[]) {
            Messenger mes = new Messenger(args[0]);
        Messenger(Socket s, String strg) {
            this.connect = s;
            CreateWindow();
            setupEvents();
            LoginData(strg);
            fram.show();
    }

  • Problem with socket connection

    have my gps reciver connected to the usb port - i have a daemon gpsd running which makes data available on tcp port 2947 for querying. when i do telnet, it gives proper data.
    but when i open a socket connection using java, it does not print anything as output. actually telnet asks for an escape charatcer so i am sending "r" initially to the server but still the program does not print anything as output.
    here is my java code -
    import java.io.*;
    import java.net.Socket;
    public class test2
    public static void main(String[] args)
    try
    Socket s = new Socket("localhost",2947);
    PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(
    s.getOutputStream())),true);
    out.println("r");
    BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream()));
    String line;
    while(true)
    line = in.readLine();
    System.out.println(line);
    catch (Exception e)
    or sometimes it even shows error as
    Exception in thread "main" java.net.SocketException: Invalid argument or cannot assign requested address
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    and this is the output which i get on telnet -
    ot@localhost ~]# telnet localhost 2947
    Trying 127.0.0.1...
    Connected to localhost.
    Escape character is '^]'.
    r
    GPSD,R=1
    $GPRMC,000212,V,18000.0000,N,00000.0000,W,0.0000,180.000,101102,,*1A
    $GPGSA,A,1,,,,,,,,,,,,,,,,*32
    $PGRME,400.00,0.00,0.00*7B
    $GPRMC,000213,V,18000.0000,N,00000.0000,W,0.0000,180.000,101102,,*1B
    $GPGSA,A,1,,,,,,,,,,,,,,,,*32
    $PGRME,400.00,0.00,0.00*7B
    $GPRMC,000214,V,18000.0000,N,00000.0000,W,0.0000,180.000,101102,,*1C
    $GPGSA,A,1,,,,,,,,,,,,,,,,*32

    Actually the problem does not seem to be in the code because i tried some basic client server programs (without any gpsd etc in picture) and even they are not working in linux though they work perfectly in windows (on the same machine). In linux it shows exception
    My socket programs dont work in linux it shows error -
    ot@localhost winc]# java parser
    Exception in thread "main" java.net.SocketException: Invalid argument or cannot assign requested address
    at java.net.PlainSocketImpl.socketConnect(Native Method)
    at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:305)
    at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:171)
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:158)
    at java.net.Socket.connect(Socket.java:452)
    at java.net.Socket.connect(Socket.java:402)
    at java.net.Socket.<init>(Socket.java:309)
    at java.net.Socket.<init>(Socket.java:124)
    at parser.main(parser.java:10)
    i have removed the firewall settings etc and it still doesnot work in linux
    what could be the cause for this?
    Sowmya

  • Problem with socket connection through Java Embedding...

    We are trying to create a simple socket connection to a socket server through BPEL PM using the Java Embedding component.
    BPEL Process : Client makes an asynchronous request. Passes an input variable. The input variable is sent to the Server Program through a socket connection through the Java embedding component.
    Server: We are running a simple Socket Server program from command prompt.
    The code below works fine as long as we do not try to receive a response from the server (Commented Code).
    If we uncomment the code and try to receive a response, it refuses to create an instance for the BPEL Process. And sometimes restarts the BPEL Server.
    Client Code:
    String msg="NONE";
    try{
    org.w3c.dom.Element input = (org.w3c.dom.Element) getVariableData("inputVariable","payload","/client:clientProcessRequest/client:input");
    msg = input.getNodeValue();
    Socket clientsoc=new Socket("ServerIP",1000);
    PrintWriter out1=new PrintWriter(clientsoc.getOutputStream());
    out1.write(msg);
    out1.flush();
    BufferedReader cin1=new BufferedReader(new InputStreamReader(clientsoc.getInputStream()));
    msg=cin1.readLine();
    setVariableData("outputVariable","payload","/client:result",new String(msg));
    clientsoc.close();
    catch(UnknownHostException e)
    System.err.println("Don't know about host: dev.");
    System.exit(1);
    catch (IOException e)
    System.err.println("Couldn't get I/O for "+ "the connection to: dev.");
    System.exit(1);
    }

    Repost

  • Problem with socket connection in midp 2.0

    hello everyone.
    I'm new one in j2me and I am learning socket connection in j2me. I'm using basic socket,datagram example wich is come with sun java wireless toolkit 2.5. for it i wrote small socket server program on c# and tested it example on my pc and its working fine. also socket server from another computer via internet working fine. But when i instal this socket example into my phone on nokia n78 (Also on nokia 5800) it's not working didn't connect to socket server.. On phone I'm using wi-fi internet. Can anybody help me with this problem? I hear it's need to modify manifest file and set appreciate pressions like this
    MIDlet-Permissions: javax.microedition.io.Connector.socket,javax.microedition.io.Connector.file.write,javax.microedition.io.Connector.ssl,javax.microedition.io.Connector.file.read,javax.microedition.io.Connector.http,javax.microedition.io.Connector.https
    is it true?
    can anybody suggest me how can i solve this problem?
    where can I read full information about socket connection specifiecs in j2me?
    Thanks.

    Maybe this can be helpful:
    [http://download-llnw.oracle.com/javame/config/cldc/ref-impl/midp2.0/jsr118/index.html]
    you can check there the Datagram interface anda DatagramConnection interface and learn a little about that.
    If the client example runs fine in the wireless toolkit emulator, it should run the same way in your phone; i suggest to try to catch some exception that maybe is hapenning and display it on a Alert screen, this in the phone.

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

  • Multiple clients on socket connection

    Hi!
    I understand that it is possible that multiple clients listen to one server (on the same port) and even write to it (then it should be a multi-threaded server).
    But i would like to refuse connectios, if one client is connected. How can I do that?
    In my case I have a (single threaded) server. Now one clients connects. The server waits to receive data from the client and answers, without ever closing the port. that works.
    Now if I connect with a second client, the openicng of the socket in the second client works fine, although the server does not seem to notice the second client. Communication is not possible between the server and the second client, and the server doesn't answer to the first client anymore, although he receives data from it.
    So, since the server does not seem to notice the second client (does not accept the connection) and I don't get an exception at the second client, what can I do?
    Thank you for your help!
    concerned Code (if you want to take a look at it):
    CLIENT:
    socket = new Socket(hostname, echo_port);
    SERVER:
    try
    ServerSocket waitingsocket = new ServerSocket(echo_port);
    try
         socket= waitingsocket.accept();
         System.out.println("Client connected");
         ReaderThread reader = new ReaderThread( this, socket );
         reader.start();          
    catch (Exception e)
    READER:
    public void run()
         while (true)
              try {
                   int bytesRead = inStream.read(inputBuffer,
                   0, inputBuffer.length);
                   readCallback.tcpUpdate(inputBuffer,bytesRead);
              catch (Exception oops)
                   readCallback.tcpUpdate(null,-1);
              

    Just to make sure this is clear: You can NOT have multiple clients on a given socket connection. You CAN have multiple clients connected to a particular port on a given server, but each client will be communicating with the server through a different of socket.
    The usual approach here is to set up a listening ServerSocket on the desired port, call accept() on it, then process the communication from the returned Socket object. This is usually done by spawning a new thread and allowing it to handle the socket communication, while the ServerSocket loops around to another accept() for the next communication.
    Here's an excellent intro to the concepts (the code is really ugly and poorly implemented, but it does a good job of explaining the overall concept). I used this as a starting point, and now (after a whole lot of development) have a pretty sweet extensible web server class that handles template expansion, etc... (I use this as a quick and dirty UI for some of my apps, instead of requiring the user to install a JSP container):
    http://developer.java.sun.com/developer/technicalArticles/Networking/Webserver/
    - K

  • How can i reuse my existing socket connection

    Hi,
    this might sound basic, it probably is:
    As part of my larger project, i have to send and recieve data to multiple socket connections.
    The thing that happens is that everytime i send data, it seems that java is creating a new stream or something (code is multithreaded)
    so as i send 4 items of data, a bit like a chat program sending 4 statements, it creates 4 different streams, instead of using the same stream. therefore when i close the connection, i get:
    java.net.SocketException: Connection reset 4 times.
    i know why.. its because i have added the:
    Socket socket=new Socket(host, port);
    BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
    PrintWriter out = new PrintWriter(new OutputStreamWriter(socket.getOutputStream()));
    bit in the same method with the
    out.println(THE DATA....);
    out.flush();
    The thing what i want to do is to create the connection one, and reuse the objects:
    out, in and socket
    to send / recieve the new data.
    please help me guys,
    thanks

    All the threads would be able to get the same reference to....
    class SocketWrapper {
         private final Object readLock = new Object();
         private final Object writeLock = new Object();
         // client side
        public SocketWrapper(String hostname, int port);
         // server side.
        public SocketWrapper(Socket);
         // send data
         public void send(Serializable object) throws IOException;
         // receive data. synchronized(writeLock);
         public Serializable getNext() throws IOException;
         // create a new socket as required, throw IllegalState if server side. synchronized(readLock)
         private void createNewSocket() throws IllegalStateException;
    }The send autoconnects as required. It then send on message/packet/object.
    The getNext autoconnects as required. It reads one message/packet/object and returns.
    This allows multiple threads to access the same socket. It allows data to be sent while a thread is blocking on a read. (Thus two locks)

Maybe you are looking for

  • Help with Using Adobe Reader with iBook G4

    I have downloaded Adobe Reader 7.0.8 several times in order to read eBooks on my G4 12"iBook using OS 10.4.7. I activated the Adobe program as directed but continue to get an error message when attempting to use the application. The message indicates

  • SYS user connects at database level, is it correct?

    My senior colleague has given me following information about the sys user. I want to know, is it correct? Since SYS user connects at the database level, therefore, on killing the active session of the SYS user,only the current statement is cancelled.

  • I can't edit song information the problem is not in all the items

    I can't edit the information of my songs like gnre, artist, etc... when I start to use itunes I had another computer, when I change of computer I decide to copy my library to a external hard disk, I don't know if this is creating the problem, will be

  • Crashes when resuming from sleep.

    I just bought my macbook 6 days ago. Occasionally, upon opening the macbook it will not be resuming from sleep but the OS will actually be rebooting itself. This happens very infrequently. In the 6 days I've been using it (and I've been using it a lo

  • IBM DB2 is easier to administer than Oracle, is it true?

    Today i found a reference , here it is http://smarterquestions.org/2011/04/why-ibm-db2-is-easier-to-administer-than-oracle/ http://blog.triton.co.uk/2010/12/db2-beats-oracle-database-in-final-task-showdown/ they are saying "IBM DB2 is easier to admin