Socket Exception when closing Server Socket Streams if Client closes first

Hi
I have 2 processes - a Server socket and a client socket. If I close the Client process first, and then try closing down the Streams on the Server process, I get a SocketException with message "Socket is closed" when I try and close the 2nd Stream. It does not matter on the order of the Stream being closed down, the exception is always thrown when I try and close the second stream. The code snippets are below:
SERVER =======
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;
public class ServerSocketTest {
public static void main(String args[]) {
try {
ServerSocket ss = new ServerSocket(9999);
Socket s = ss.accept();
// Get refs to streams...
InputStream is = s.getInputStream();
OutputStream os = s.getOutputStream();
// sleep to let client shutdown first...
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
System.err.println(e);
System.err.println("B4 inClose: isBound=" + s.isBound());
System.err.println("B4 inClose: isClosed=" + s.isClosed());
System.err.println("B4 inClose: isConnected=" + s.isConnected());
System.err.println("B4 inClose: isInputShutdown=" + s.isInputShutdown());
System.err.println("B4 inClose: isOutputShutdown=" + s.isOutputShutdown());
s.getInputStream().close();
System.err.println("After inClose: isBound=" + s.isBound());
System.err.println("After inClose: isClosed=" + s.isClosed());
System.err.println("After inClose: isConnected=" + s.isConnected());
System.err.println("After inClose: isInputShutdown=" + s.isInputShutdown());
System.err.println("After inClose: isOutputShutdown=" + s.isOutputShutdown());
s.getOutputStream().close(); // will break here with SocketException!
System.err.println("After outClose: isBound=" + s.isBound());
System.err.println("After outClose: isClosed=" + s.isClosed());
System.err.println("After outClose: isConnected=" + s.isConnected());
System.err.println("After outClose: isInputShutdown=" + s.isInputShutdown());
System.err.println("After outClose: isOutputShutdown=" + s.isOutputShutdown());
s.close();
} catch (Exception e) {
System.err.println(e);
CLIENT ======
import java.net.Socket;
public class ClientSocket {
public static void main(String args[]) {
try {
Socket s = new Socket("localhost", 9999);
try {
// sleep to leave connection up for a while...
Thread.sleep(2000);
} catch (InterruptedException e) {
System.err.println(e);
s.close();
} catch (Exception e) {
System.err.println(e);
The debug shows that isClosed() is set to 'true' after the first call to s.getInputStream().close(). The Sun API Socket class getOutputStream() has a call to isClosed() at the start of the method - it then throws the SocketException that I get. Why does the SocketImpl do this before I get a chance to call a.getOutputStream().close()?
One final thing, the calls to s.isInputShutdown() and s.isOuputShutdown always seem to return false even if the Streams have had their .close() method called.
Any ideas/help here greatly appreciated.
Thanks
Gaz

Ok, I know what's going on now - I needed something to do on Friday afternoon anyhow!
Basically if you call either getOutputStream.close() or getInputStream().close(), the underlying Sun implementation will close the Socket.
Here's what's happening under the covers in the Sun code:
s.getInputStream() is called on the Socket class.
The Socket class holds a reference to the SocketImpl class.
The SocketImpl class is abstract and forces sublclasses to extend it' s getInputStream() method.
The PlainSocketImpl extends SocketImpl.
PlainSocketImpl has a getInputStream() method that returns a SocketInputStream. When the stream is created for the first time, the PlainSocketImpl object is passed into the Constructor.
The SocketInputStream class has a close() method on it. The snippet of code below shows how the socket is closed:
<pre>
* Closes the stream.
private boolean closing = false;
public void close() throws IOException {
     // Prevent recursion. See BugId 4484411
     if (closing)
     return;
     closing = true;
     if (socket != null) {
     if (!socket.isClosed())
          socket.close();
     } else
     impl.close();
     closing = false;
</pre>
So, it seems that out PlainSocketImpl is getting closed for us, hence the SocketException being thrown in Socket.getOutputStream() when I call it after Socket.getInputStream()/
I've not had a look at the reason why the calls to s.isInputShutdown() and s.isOuputShutdown always seem to return false even if the Streams have had their .close() method called though - any thoughts appreciated.
Thanks
G

Similar Messages

  • Socket Exception when closing the console

    Hi ,
    I'm running WLC & P Server 3.5/WL 6.1 in the following environment
    Weblogic Version: WebLogic Server 6.1 SP1
    JDK Vendor: Blackdown Java-Linux Team
    JDK Version: 1.3.1
    Operating System: Linux
    and I'm getting very often this exception when closing the console
    <Dec 30, 2001 2:21:48 PM EST> <Error> <HTTP> <Connection failure
    java.net.SocketException: Error in poll for fd: '60', revents: '24'
    at
    weblogic.socket.PosixSocketMuxer.deliverBadNews(PosixSocketMuxer.java:429)
    at
    weblogic.socket.PosixSocketMuxer.processSockets(PosixSocketMuxer.java:384)
    at
    weblogic.socket.SocketReaderRequest.execute(SocketReaderRequest.java:24)
    at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:139)
    at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
    >
    I also get the same behaviour under WL 6.1 alone when closing the console.
    Does anybody know what this means?
    Thanks,
    Dan

    Ooops, sorry for the repost.
    I can see my first post on the newsgroup when I access it with the browser
    http://newsgroups.bea.com/cgi-bin/dnewsweb?cmd=article&group=weblogic.develo
    per.interest.personalization&item=1650&utag= )
    but I cannot see it when using my newsgroup reader (Outlook Express).
    Dan
    "Dan" <[email protected]> wrote in message news:[email protected]..
    Hi ,
    I'm running WLC & P Server 3.5/WL 6.1 in the following environment
    Weblogic Version: WebLogic Server 6.1 SP1
    JDK Vendor: Blackdown Java-Linux Team
    JDK Version: 1.3.1
    Operating System: Linux
    and I'm getting very often this exception when closing the console
    <Dec 30, 2001 2:21:48 PM EST> <Error> <HTTP> <Connection failure
    java.net.SocketException: Error in poll for fd: '60', revents: '24'
    at
    weblogic.socket.PosixSocketMuxer.deliverBadNews(PosixSocketMuxer.java:429)
    at
    weblogic.socket.PosixSocketMuxer.processSockets(PosixSocketMuxer.java:384)
    at
    weblogic.socket.SocketReaderRequest.execute(SocketReaderRequest.java:24)
    at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:139)
    at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
    >
    I also get the same behaviour under WL 6.1 alone when closing the console.
    Does anybody know what this means?
    Thanks,
    Dan

  • Socket Exception in Admin Server Logs

    Hi All,
    We are facing a socket exception in Admin Server log. PFB for the exception logs:
    [2011-12-26T00:36:21.793-06:00] [AdminServer] [WARNING] [] [oracle.adfinternal.view.faces.renderkit.rich.TreeRendererUtils] [tid: [ACTIVE].ExecuteThread: '44' for queue: 'weblogic.kernel.Default (self-tuning)'] [userId: weblogic] [ecid: 0000JHt5O2e6yGD_n95EiZ1Ev5590005ms,0] [APP: em] [dcid: 88568bb1654f17ca:22e22403:1344b1dc283:-7ffe-0000000000042162] Context menu child is not a RichMenu
    [2011-12-26T00:39:05.574-06:00] [AdminServer] [ERROR] [] [oracle.adfinternal.view.faces.config.rich.RegistrationConfigurator] [tid: [ACTIVE].ExecuteThread: '44' for queue: 'weblogic.kernel.Default (self-tuning)'] [userId: weblogic] [ecid: 0000JHt60Xn6yGD_n95EiZ1Ev5590005nI,0] [APP: em] [dcid: 88568bb1654f17ca:22e22403:1344b1dc283:-7ffe-0000000000042182] Server Exception during PPR, #126[[
    java.net.SocketException: Write failed: Broken pipe
         at jrockit.net.SocketNativeIO.writeBytesPinned(Native Method)
         at jrockit.net.SocketNativeIO.socketWrite(SocketNativeIO.java:46)
         at java.net.SocketOutputStream.socketWrite0(SocketOutputStream.java)
         at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
         at java.net.SocketOutputStream.write(SocketOutputStream.java:136)
         at weblogic.servlet.internal.ChunkOutput.writeChunkTransfer(ChunkOutput.java:507)
         at weblogic.servlet.internal.ChunkOutput.writeChunks(ChunkOutput.java:486)
         at weblogic.servlet.internal.ChunkOutput.flush(ChunkOutput.java:382)
         at weblogic.servlet.internal.CharsetChunkOutput.flush(CharsetChunkOutput.java:313)
         at weblogic.servlet.internal.ChunkOutputWrapper.flush(ChunkOutputWrapper.java:174)
         at weblogic.servlet.internal.ServletOutputStreamImpl.flush(ServletOutputStreamImpl.java:111)
         at weblogic.servlet.internal.ServletResponseImpl.flushBuffer(ServletResponseImpl.java:185)
         at javax.servlet.ServletResponseWrapper.flushBuffer(ServletResponseWrapper.java:176)
         at javax.servlet.ServletResponseWrapper.flushBuffer(ServletResponseWrapper.java:176)
         at com.sun.faces.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:229)
         at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:189)
         at org.apache.myfaces.trinidadinternal.application.ViewHandlerImpl.renderView(ViewHandlerImpl.java:193)
         at oracle.sysman.emSDK.adfext.ctlr.EMViewHandlerImpl.renderView(EMViewHandlerImpl.java:149)
         at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl._renderResponse(LifecycleImpl.java:710)
         at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl._executePhase(LifecycleImpl.java:273)
         at oracle.adfinternal.view.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:205)
         at javax.faces.webapp.FacesServlet.service(FacesServlet.java:266)
         at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227)
         at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125)
         at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:300)
         at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:26)
         at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
         at oracle.adfinternal.view.faces.webapp.rich.RegistrationFilter.doFilter(RegistrationFilter.java:97)
         at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl$FilterListChain.doFilter(TrinidadFilterImpl.java:420)
         at oracle.adfinternal.view.faces.activedata.AdsFilter.doFilter(AdsFilter.java:60)
         at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl$FilterListChain.doFilter(TrinidadFilterImpl.java:420)
         at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl._doFilterImpl(TrinidadFilterImpl.java:247)
         at org.apache.myfaces.trinidadinternal.webapp.TrinidadFilterImpl.doFilter(TrinidadFilterImpl.java:157)
         at org.apache.myfaces.trinidad.webapp.TrinidadFilter.doFilter(TrinidadFilter.java:92)
         at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
         at oracle.help.web.rich.OHWFilter.doFilter(Unknown Source)
         at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
         at oracle.sysman.emSDK.license.LicenseFilter.doFilter(LicenseFilter.java:164)
         at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
         at oracle.adf.model.servlet.ADFBindingFilter.doFilter(ADFBindingFilter.java:191)
         at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
         at oracle.sysman.emas.fwk.MASConnectionFilter.doFilter(MASConnectionFilter.java:41)
         at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
         at oracle.adf.library.webapp.LibraryFilter.doFilter(LibraryFilter.java:159)
         at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
         at oracle.sysman.eml.app.AuditServletFilter.doFilter(AuditServletFilter.java:179)
         at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
         at oracle.sysman.eml.app.EMRepLoginFilter.doFilter(EMRepLoginFilter.java:203)
         at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
         at oracle.sysman.core.app.perf.PerfFilter.doFilter(PerfFilter.java:141)
         at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
         at oracle.sysman.eml.app.ContextInitFilter.doFilter(ContextInitFilter.java:542)
         at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
         at oracle.dms.wls.DMSServletFilter.doFilter(DMSServletFilter.java:330)
         at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
         at weblogic.servlet.internal.RequestEventsFilter.doFilter(RequestEventsFilter.java:27)
         at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:56)
         at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.doIt(WebAppServletContext.java:3684)
         at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3650)
         at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
         at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121)
         at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2268)
         at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2174)
         at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1446)
         at weblogic.work.ExecuteThread.execute(ExecuteThread.java:201)
         at weblogic.work.ExecuteThread.run(ExecuteThread.java:173)
    [2011-12-26T00:39:07.687-06:00] [AdminServer] [WARNING] [] [oracle.adfinternal.view.faces.renderkit.rich.TreeRendererUtils] [tid: [ACTIVE].ExecuteThread: '44' for queue: 'weblogic.kernel.Default (self-tuning)'] [userId: weblogic] [ecid: 0000JHt60co6yGD_n95EiZ1Ev5590005nJ,0] [APP: em] [dcid: 88568bb1654f17ca:22e22403:1344b1dc283:-7ffe-0000000000042183] Context menu child is not a RichMenu
    [2011-12-26T00:41:42.485-06:00] [AdminServer] [WARNING] [] [oracle.adfinternal.view.faces.renderkit.rich.TreeRendererUtils] [tid: [ACTIVE].ExecuteThread: '65' for queue: 'weblogic.kernel.Default (self-tuning)'] [userId: weblogic] [ecid: 0000JHt6aR46yGD_n95EiZ1Ev5590005na,0] [APP: em] [dcid: 88568bb1654f17ca:22e22403:1344b1dc283:-7ffe-0000000000042198] Context menu child is not a RichMenu
    [2011-12-26T10:30:56.963-06:00] [AdminServer] [WARNING] [] [org.apache.myfaces.trinidad.webapp.ResourceServlet] [tid: [ACTIVE].ExecuteThread: '30' for queue: 'weblogic.kernel.Default (self-tuning)'] [userId: weblogic] [ecid: 0000JHvDUMs6yGD_n95EiZ1Ev5590005q5,0] [APP: em] [dcid: 88568bb1654f17ca:22e22403:1344b1dc283:-7ffe-0000000000046718] ResourceServlet._setHeaders(): Content type for /bi/jsLibs/engine_20100410.swf is NULL![[
    Cause: Unknown file extension
    Kindly provide us a solution to avoid this issue.
    Thanks & Regards,
    Prabhu

    It seems that chunking is causing the issue. In the HTTP Transport Configuration Options of your business service, disable the setting "Use Chunked Streaming Mode"
    Regards,
    Anuj

  • "No more data to read from socket" exception when testing connections

    Hi,
    I will appriciate your help with the following problem.
    We have the follwoing errors in the weblogic.log (We are using weblogic 8.1.0.2 and Oracle 9.2.0.3)
    ####<Dec 20, 2006 10:47:49 AM EET> <Info> <JDBC> <ep> <mfserver> <Thread-14> <<WLS Kernel>> <> <BEA-001128> <Connection for pool "oraclePool" closed.>
    ####<Dec 20, 2006 10:47:49 AM EET> <Info> <JDBC> <ep > <mfserver> <Thread-14> <<WLS Kernel>> <> <BEA-001067> <Connection for pool "oraclePool" refreshed.>
    ####<Dec 20, 2006 10:47:51 AM EET> <Error> <JDBC> <ep > <mfserver> <Thread-14> <<WLS Kernel>> <> <BEA-001112> <Test "select count(*) from DUAL" set up for pool "oraclePool" failed with exception: "java.sql.SQLException: No more data to read from socket".>
    ####<Dec 20, 2006 10:47:51 AM EET> <Error> <JDBC> <ep > <mfserver> <Thread-14> <<WLS Kernel>> <> <BEA-001131> <Received an exception when closing a cached statement for the pool "oraclePool": java.sql.SQLException: Io exception: Broken pipe.>
    These exception occures every hour after the connection pool is being closed and refreshed.
    Also there are a lot of the follwoing warnning in the log :
    <BEA-001074><A JDBC pool connection leak was detected.
    Does these two problems connected? What can we do in order to solve it?
    Thanks
    Edited by RF123 at 01/28/2007 3:41 AM

    R F wrote:
    Hi,
    I will appriciate your help with the following problem.
    We have the follwoing errors in the weblogic.log (We are using weblogic 8.1.0.2 and Oracle 9.2.0.3)
    ####<Dec 20, 2006 10:47:49 AM EET> <Info> <JDBC> <ep> <mfserver> <Thread-14> <<WLS Kernel>
    <> <BEA-001128> <Connection for pool "oraclePool" closed.>
    ####<Dec 20, 2006 10:47:49 AM EET> <Info> <JDBC> <ep > <mfserver> <Thread-14> <<WLS Kernel>
    <> <BEA-001067> <Connection for pool "oraclePool" refreshed.>
    ####<Dec 20, 2006 10:47:51 AM EET> <Error> <JDBC> <ep > <mfserver> <Thread-14> <<WLS Kernel>
    <> <BEA-001112> <Test "select count(*) from DUAL" set up for pool "oraclePool" failed with exception:
    "java.sql.SQLException: No more data to read from socket".>
    ####<Dec 20, 2006 10:47:51 AM EET> <Error> <JDBC> <ep > <mfserver> <Thread-14> <<WLS Kernel>
    <> <BEA-001131> <Received an exception when closing a cached statement for the pool "oraclePool":
    java.sql.SQLException: Io exception: Broken pipe.>
    These exception occures every hour after the connection pool is being closed and refreshed.
    Also there are a lot of the follwoing warnning in the log :
    <BEA-001074><A JDBC pool connection leak was detected.
    Does these two problems connected? What can we do in order to solve it?Hi. The problems are not directly related, but may have the same cause.
    Something is killing your DBMS connections out from under the driver.
    Do you have a firewall between WLS and the DBMS, or a flakey network?
    Contact BEA support to get the 8.1sp2 patch for getting meaningful
    connection leak traces (CR209251_81sp2.jar). When that patch is installed
    the leak messages should show a full stack trace of the application code
    where the connection was obtained. It is that application code that
    somehow failed to close the pool connection, causing a pool leak. I
    suspect that the application code got an unexpected exception, such as
    when/if the DBMS/network/firewall killed a connection. In this case I
    believe the application went through an exception-handling path that
    forgot to close the connection.
    Joe

  • SocketException when closing a Socket

    hello all,
    i have written code for printing to a printer on the network using Sockets...
    after printing the data, i do following:
    - close PrintWriter
    - call socket.shutdownOutput
    - call socket.close
    i am getting an exception when i call socket.shutdownOutput, saying
    java.net.SocketException: Socket is closed
         at java.net.Socket.shutdownOutput(Socket.java:1309)
    is the socket trying to close the PrintWriter that has already been closed?
    anyone has any ideas?
    thanx in advance and regards
    marco

    Instead of closing the PrintWriter just flush it. Then do shutdownOutput, then close either the PrintWriter or the socket - you don't need to do both.

  • Use HTTP Dynamic Streaming (HDS) and HTTP Live Streaming (HLS) to serve live streams to clients over HTTP

    I have created a live stream of a video and it gets stored in live folder.
    Now i need to use HTTP Dynamic Streaming (HDS) and HTTP Live Streaming (HLS) to serve live streams to clients over HTTP, publish the streams to the HTTP Live Packager service on Flash Media Server.
    So what necessary steps do I  need to follow to do that ??

    You need to generate a manifest file using Configurator tool and placed it under the webroot directory.
    C:\Program Files\Adobe\Flash Media Server 4.5\tools\f4mconfig\configurator

  • When closing "Word" it does not fully close and I have to force close it to shut down my computer, any suggestions?

    When closing "Word" it does not fully close and I have to force close it to shut down my computer, any suggestions?

    Sounds like Word is corrupt, I would uninstall the app and then reinstall. Also there is a MS Office for Mac forum,  you can find it at: Office for Mac Product Forums

  • No exception is thrown when my server socket dies

    I have a server application running on sunOS 5.7.
    To this I have both Windows and SunOS clients connected via TCP/IP. (Server built with jdk 1.2.2 and client with 1.3.0)
    If the Server socket dies an exception is thrown in the windows clients but not in the sunOS client.
    I need the exception to be thrown in the sunOS as well.
    Is there anybody who knows how to get this done?
    Thanks in advance.
    /Henrik

    You could poll the connection to see if its there.
    If you want the client to register the event then have your client create a sort of listener of your own when it connects. By 'sort of listener' I mean extend the thread class and have it check the connection is not null every n seconds. If it is null then raise the exception yourself.
    Would this do it?
    Rob.

  • Detecting unsent data when closing a socket

    I'm currently using a non-blocking socket to send data to a remote server. Whenever the application detects that the connection has been closed remotely, it will close the local connection, however netstat reports that there is unsent data still in the TCP/IP buffers.
    What I'd like to do is check within the application whether there is any unsent data at the time the socket is closed. I've read that SO_LINGER can be used in such circumstances and then checking the return code on closing the socket, but it's unclear whether this will work in non-blocking mode.

    Instead of closing the PrintWriter just flush it. Then do shutdownOutput, then close either the PrintWriter or the socket - you don't need to do both.

  • How to Create a Single Backend Socket connectivity in a Server Socket Pgm

    Hi Everybody,
    I have a written a Server Socket which connects to back end socket and receiving the data and sending back to the front end. But as per my client requirement i need to create only one socket at the back end. But the code I have written is creating new sockets for each request. Is there any way to use the single client socket connection for all the transactions. I have attached the sample code for the reference.
    import java.io.*;
    import java.net.*;
    import java.nio.ByteBuffer;
    import java.nio.channels.SocketChannel;
    public class serl implements Runnable
    ServerSocket serversocket;
    Socket clientsoc;
    Socket fromclient;
    PrintStream streamtoclient;
    BufferedReader streamfromclient;
    SocketChannel socket_channel=null;
    Thread thread;
    public serl()
    try
    serversocket = new ServerSocket(1001);//create socket
    clientsoc = new Socket("10.100.53.145",200);
    socket_channel = clientsoc.getChannel();
    catch(Exception e)
    System.out.println("Socket could not be created "+e);
    thread=new Thread(this);
    thread.start();
    public void run()
    try
    while(true)
         PrintStream streamtobackend=null;
         BufferedReader streamfrombackend = null;
    fromclient=serversocket.accept();//accept connection fromclient
    streamfromclient=new BufferedReader(new InputStreamReader((fromclient.getInputStream())));
    //create a input stream for the socket
    streamtoclient=new PrintStream(fromclient.getOutputStream());
    //create an a output stream for the socket
    String str=streamfromclient.readLine();
    //read the message sent by client
    System.out.println("Output Input From Vtcpd "+str);
    streamtobackend.print(str);
    streamtobackend = new PrintStream(clientsoc.getOutputStream());
    //create an a output stream for the backend socket
    streamfrombackend = new BufferedReader(new InputStreamReader(clientsoc.getInputStream()));
    //create a input stream for the backend socket
    str=streamfrombackend.readLine();
    System.out.println("Output From Backend Client"+str);
    streamtoclient.println(str);
    }//end of while
    catch(Exception e)
    System.out.println("Exception "+e);
    finally
    try
    fromclient.close();
    catch(Exception e)
    System.out.println("could not close connection "+e);
    public static void main(String ar[])
    new serl();
    }

    Srikandh,
    Create a singelton pattern for you socket ( IP, port, etc..) and each time you read the input stream and write to the output stream, do the following to the socket to reset it in the working thread
    fromclient.getInputStream().mark(0);
    fromclient.getInputStream().reset();Hope this could help
    Regards,
    Alan Mehio
    London,UK

  • Exception when upgrading server?

    I am trying to diagnose a problem with my application which is a simple applet Swing GUI and servlet middle tier. The application was recently moved to a faster server and from a WinNT to Win2000 Server environment. The webserver was also upgraded from Netscape Enterprise version 4.1 to version 6.1. Suddenly I am now experiencing an Exception when the servlet tries to deserialize the Vector being sent from the client.
    The GUI code for servlet connections and the servlet receiving code are pasted below. The EOFException stack trace is also below.
    Please respond if you have any suggestions on solutions, work arounds, or any ideas that might narrow down the OS, Webserver, network, or code.
    This exception is thrown at random times. Two successive calls with the exact same parameters may fail for one call but not the other.
    To rule out the webserver, I have re-installed it and the error still occurs.
    Originally JRE 1.4 was used by the upgraded webserver, however, I have switched back to JRE 1.3.1. Still no help.
    I am beginning to wonder if Win2000Server might need to be re-installed.
    Any comments are appreciated.
    Thank you!
    Server Environment
    Win2000 Server SP4
    Dell Poweredge 2500 (1.4Ghz dual )with 1 GB RAM
    Netscape Enterprise Server 6.1 SP6
    https
    JRE 1.3.1_06
    //******  CLIENT SIDE  ******//
    import java.io.*;
    import java.net.*;
    public class Comm
        public Comm( String anHTTPAddress ) throws MalformedURLException, Exception
                this.url = new URL( anHTTPAddress );
                this.uc = this.url.openConnection();
                this.uc.setDoOutput( true );
                this.uc.setDoInput( true );
                this.uc.setAllowUserInteraction( false );
         this.uc.setUseCaches( false );
           this.uc.setRequestProperty( "Content-Type", "application/octet-stream" );
        public void sendObject(java.util.Vector anObject)     throws IOException
         ObjectOutput out = new ObjectOutputStream( uc.getOutputStream() );
         out.writeObject( anObject );
         out.flush();
         out.close();
        public Object readObject() throws ClassNotFoundException, IOException
         ObjectInput in = new ObjectInputStream( uc.getInputStream() );
         Object returnObject = in.readObject();
            in.close();
         return returnObject;
        private URL url;
        private URLConnection uc;
    //******  SERVER SIDE  ******//
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    import java.util.Vector;
    public class MyServlet extends HttpServlet
        public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException
         ObjectInput objectIn      = null;
         ObjectOutput objectOut      = null;
         String operation      = null;
         Vector results           = null;
         Vector msgVector      = null;
         try {
              objectIn = new ObjectInputStream( new BufferedInputStream(req.getInputStream()) );
    // --->  this point is never reached -- see error below
              msgVector = (Vector)objectIn.readObject();
              objectOut      = new ObjectOutputStream( res.getOutputStream() );
               * Process the input to produce results
              res.setContentType("application/octet-stream");
              results = new Vector(); // where the result is placed
         catch(Exception e) {
              e.printStackTrace();
              results = new ErrorMessage(); // error message vector!
         objectOut.writeObject( results );
         objectOut.flush();
         objectOut.close();     
    //some snipping
    //******  ERROR  ******//
    java.io.StreamCorruptedException: Caught EOFException while reading the
    stream header
         at java.io.ObjectInputStream.readStreamHeader(ObjectInputStream.java:840)
         at java.io.ObjectInputStream.<init>(ObjectInputStream.java:163)
         at MyServlet.doPost(MyServlet.java:25)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
         at
    com.netscape.server.http.servlet.NSServletRunner.invokeServletService(NSServletRunner.java:894)
         at
    com.netscape.server.http.servlet.NSServletRunner.Service(NSServletRunner.java:461)

    Timing could not have been worse for the upgrade. Of course it would have to be a microsoft problem.
    patches for patches....
    http://support.microsoft.com/default.aspx?scid=kb;en-us;831167&Product=ie600

  • Interesting! C client socket communicating with java server sockets after..

    Hi,
    I have a client(in C) open a socket and server(in java; jvm 1.2) listening on the same port(e.g. 4444) accepts the request and establishes a socket conn. Now the sockets are kept open indefinitely. If I kill the server process and bring it backup, the client(in C) cannot communicate with the server(in java).
    Why would this be happening? Aren't the server socket garbage collected?
    How do I make sure that the next time I bring up the server again, the client communicates with it.
    Any inputs is really appreciated.
    thanks
    atul.

    Check the client is closing the connection before it stops.
    I've had similar problems with JDBC before where if you don't explicitly close the connection it remains bound to the port, hence if your client only ever tries to connect to that port it will fail.
    I think.
    MrChris

  • Socket Exception in Weblogic Server when invoking webservice via JPD

     

    We faced with the similar issue in WLS 7.X after below Assertion error after restoring services we were able to resolve this issue for time being as per the weblogic there is a patch provided by BEA and this sort of issue is resolved.
    This issue has been identified and updated under cars CR103525
    Regards,
    CSR
    BEA Analyst

  • Socket Timeout when reading from post stream

    I get the following error when a servlet tries to read an object from the post stream.
    Is there a way to set any timeout values on, say a socket, or static variable on
    any weblogic SocketImpl..?
    Appreciate any help.
    Thanks-
    Rama
    java.io.InterruptedIOException: Read timed out
    at java.net.SocketInputStream.socketRead(Native Method)
    at java.net.SocketInputStream.read(SocketInputStream.java:86)
    at weblogic.servlet.internal.PostInputStream.read(PostInputStream.java:124)
    at weblogic.servlet.internal.ServletInputStreamImpl.read(ServletInputStreamImpl.java:97)
    at java.io.ObjectInputStream.read(ObjectInputStream.java:1835)

    Was successful in setting the duration parameter in the HTTP tab of the server.
    However, when accessing the app (servlet) via iPlanet proxy, it still fails. I have
    to check on similar settings on that side.
    Do you have hints for me ?
    Thanks for your posting, Dave.
    Rama
    "Dave Martin" <[email protected]> wrote:
    >
    Rama:
    Try changing the Post Timeout Secs option under the HTTP tab for your server
    in the
    WebLogic Admin console. You could bump out the Duration on the HTTP connection
    while
    you're at it. Not sure if these will have a side effect on what you want
    to change,
    but worth a shot.
    "Rama Raghavan" <[email protected]> wrote:
    I get the following error when a servlet tries to read an object from the
    post stream.
    Is there a way to set any timeout values on, say a socket, or static variable
    on
    any weblogic SocketImpl..?
    Appreciate any help.
    Thanks-
    Rama
    java.io.InterruptedIOException: Read timed out
    at java.net.SocketInputStream.socketRead(Native Method)
    at java.net.SocketInputStream.read(SocketInputStream.java:86)
    at weblogic.servlet.internal.PostInputStream.read(PostInputStream.java:124)
    at weblogic.servlet.internal.ServletInputStreamImpl.read(ServletInputStreamImpl.java:97)
    at java.io.ObjectInputStream.read(ObjectInputStream.java:1835)

  • Exception when closing an Applet window

    Hi,
    Every one.....
    I have added Swing components to the JApplet. Everything is fine with the program . But when i am closing the appletviewer window it is throwing the following exception :
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException: component argument pData
         at sun.awt.windows.Win32SurfaceData.initOps(Native Method)
         at sun.awt.windows.Win32SurfaceData.<init>(Unknown Source)
         at sun.awt.windows.Win32SurfaceData.createData(Unknown Source)
         at sun.awt.Win32GraphicsConfig.createSurfaceData(Unknown Source)
         at sun.awt.windows.WComponentPeer.replaceSurfaceData(Unknown Source)
         at sun.awt.windows.WComponentPeer.replaceSurfaceData(Unknown Source)
         at sun.awt.windows.WComponentPeer$2.run(Unknown Source)
         at java.awt.event.InvocationEvent.dispatch(Unknown Source)
         at java.awt.EventQueue.dispatchEvent(Unknown Source)
         at java.awt.EventDispatchThread.pumpOneEventForHierarchy(Unknown Source)
         at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
         at java.awt.EventDispatchThread.run(Unknown Source)
    So how to resolve this one, can anyone ?
    Bye

    I could be proven wrong, but I think you can use hide() and show() for your windows. You could make a windowListener that when a user tries to close the window you would have it hide that window instead, and show the underlying window:
    http://java.sun.com/docs/books/tutorial/uiswing/events/windowlistener.html
    You might also want to make the new window that pops up a modal dialog window.
    http://java.sun.com/products/jlf/ed2/book/HIG.Dialogs3.html
    Hope that helps.

Maybe you are looking for