Socket.shutdownOutput() closes socket inside JVM

Dear friends,
We have a java class which uses the Socket class. Our class does a Socket.shutdownOutput() to indicate that the sending of data is over and the reply may start. It works just fine outside Oracle, but when the class is loaded in the database the shutdownOutput() method apparently causes the socket to be closed. Below is a sample of the code and its output. The user has JAVAUSERPRIV and JAVASYSPRIV granted, and I even tried JAVA_ADMIN without success. The Oracle versions tested were 10.2.0.1 (Windows) and 10.2.0.2 (AIX). Does anybody know what can be happening ? Thanks in advance.
Code:
Socket sockICM = new Socket("192.168.1.133", 5010);
byte byxml[] = hmapICM.toXMLString().getBytes();
System.out.println("1");
InputStream isXmlOut = sockICM.getInputStream();
sockICM.getOutputStream().write(byxml);
System.out.println("1.5");
sockICM.shutdownOutput();
System.out.println("socket.isOutputShutdown(): " + sockICM.isOutputShutdown());
System.out.println("socket.isClosed(): " + sockICM.isClosed());
System.out.println("2");
byte b[] = new byte[1000];
InputStream isXmlOut = sockICM.getInputStream();
System.out.println("3");
ByteArrayOutputStream bos = new ByteArrayOutputStream();
System.out.println("4");
try
int q;
while((q = isXmlOut.read(b)) != -1)
bos.write(b, 0, q);
System.out.println("leu: " + bos.toString());
catch(Exception io){
System.out.println("err=" + io.toString());
Output:
1
1.5
socket.isOutputShutdown(): true
socket.isClosed(): false
2
3
4
err=java.net.SocketException: Socket is closed
/****************************************************/

Thank you for the answer, Kuassi, I am going to do that. One more piece of information is that my printStackTrace shows the following:
java.net.SocketException: Socket is closed
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.read(SocketInputStream.java:129)
at java.net.SocketInputStream.read(SocketInputStream.java:90)
at kiman.socktest.test(socktest:76)
Do you know what does the "Native Method" on second line mean ? I think my problem
is related to that somehow.

Similar Messages

  • Close socket hangs in SunOS5.6

    The close() function is hanging when I attempt to close a socket. I have a small multi-threaded program, which I will attach below, which replicates the problem. Basically, the program creates a thread which listens for a datagram from a socket using the recvfrom() function. When the main thread attempts to close the socket being listened to, the close() function never returns. My guess is the recvfrom() function is doing some kind of blocking and somehow needs to be told to quit waiting. However, I'm not sure how one does this. Any ideas are greatly appreciated.
    Sun tech. support recommended installing some patches we are missing. While that may ultimately be the solution, I would like to avoid doing so because this would affect multiple products we are developing and many of our customers.
    The related portion of the code is:
    main()
    /* create thread using pthread_create() */
    while (1) {
    fgets(c, sizeof(c), stdin);
    if (c[0] == '\n')
    break;
    fprintf(stderr, "Closing socket\n");
    close(sockfd);
    exit(0);
    void wait_awhile(void) {
    char buff[MAXLINE];
    int n;
    fprintf(stderr, "\nIN THREAD: prior to socket call\n");
    sockfd = socket(AF_INET, SOCK_DGRAM, 0);
    if (sockfd < 0) {
    fprintf(stderr, "could not create socket\n");
    exit(0);
    /* Get the server's socket address */
    bzero((struct sockaddr_in *)&servaddr, sizeof(servaddr));
    clientaddr_len = sizeof(struct sockaddr_in);
    servaddr.sin_family = AF_INET;
    servaddr.sin_port = htons(3500);
    servaddr.sin_addr.s_addr = inet_addr(ip_address);
    /* Bind it to the port */
    fprintf(stderr, "IN THREAD: Binding socket\n");
    if (bind(sockfd, (SA *) &servaddr, sizeof(servaddr)) < 0)
    close(sockfd);
    fprintf(stderr, "could not bind socket\n");
    exit(0);
    while (1)
    fprintf(stderr, "IN THREAD: Waiting for datagram\n");
    if ( (n = recvfrom(sockfd, buff, MAXLINE, 0, (SA *)&clientaddr, &clientaddr_len)) < 0)
    close(sockfd);
    }

    "Shirley" <[email protected]> wrote:
    >
    "Khalid" <[email protected]> wrote:
    We seem to have close wait problem in extreme load where apache/weblogic
    hold the
    tread so the socket cannot be closed. Does anyone know how to fix this
    problem.
    It seems like after in runs out of thread the server crashes.
    Have you fixed this problem you were facing ,because we are facing exactly
    the
    same problem.Did you find any solution .If so please do let us know
    Cheers
    Shirley RemediosWe had the same problem and reduced the number of sockets in this state by reducing
    the time to wait before closing the sockets. On Solaris we set 'tcp_time_wait_interval'
    to 30000 (30 seconds) on the web and app servers.

  • Sockets write/close operations hangs application

    Hi!
    I've got a trouble with my web-application. It'a s chat system, that uses Keep-Alive connections for messages output and that recieves messages through another socket.
    Everything is fine with receiving messages. But after message is received, I need to send it to all recepients. So, I use Socket.write() method. If writing is failed, or user is logged off, I use Socket.close().
    Problem is, that sometimes Socket.write() and Socket.close() are blocking their threads.
    How can I avoid such a blocking behaviour?
    If I'll rewrite everything to use not sockets, but socket channels, can it help to solve my problem?
    Thanks.

    If writes are blocking it can only mean that readers aren't reading. Fix that, and forget about the syncrhonization suggestion which is nonsense.
    You can also use NIO in non-blocking mode to avoid blocking in writes, and it does lead to more scalable applications, but be prepared for about a 10x increase in complexity.

  • Does closing socket with close() also closes the outputStream and inputStre

    hi i have a simple query
    does closing socket with close() also closes the outputStream and inputStream() associated with the socket

    Yes.

  • Comunication question for socket server and socket client

    I created a simple socket server and a socket client
    The server receive request from server and send same request back to the client.
    Please see example code as below:
    package socket;
    import java.net.*;
    import java.io.*;
    public class SimpleServer {
    public SimpleServer(int listen_port) {
    this.listen_port = listen_port;
    public static void main(String[] args) {
    SimpleServer server = new SimpleServer(4444);
    server.acceptConnections();
    public void acceptConnections() {
    try {
    ServerSocket server = new ServerSocket(listen_port);
    Socket incomingConnection = null;
    while (true) {
    incomingConnection = server.accept();
    handleConnection(incomingConnection);
    } catch (BindException e) {
    System.out.println("Unable to bind to port " + listen_port);
    } catch (IOException e) {
    System.out.println("Unable to instantiate a ServerSocket on port: " + listen_port);
    public void handleConnection(Socket incomingConnection) {
    try {
    InputStream inputFromSocket = incomingConnection.getInputStream();
    BufferedReader streamReader = new BufferedReader(new InputStreamReader(inputFromSocket));
    PrintWriter streamWriter = new PrintWriter(incomingConnection.getOutputStream());
    StringBuffer sb = new StringBuffer();
    String line = null;
    int i = 0;
    while((line=streamReader.readLine())!=null){
    streamWriter.println(line);
    break;
    streamWriter.close();
    streamReader.close();
    incomingConnection.close();
    } catch (Exception e) {
    protected int listen_port;
    //socket client
    package socket;
    import java.io.*;
    import java.net.*;
    import java.util.Iterator;
    import java.util.List;
    import java.math.*;
    public class Simple {
    public Simple(String host_ip, int host_port) {
    this.host_ip = host_ip;
    this.host_port = host_port;
    public static void main(String[] args) {
    Simple simple = new Simple("192.168.254.134", 4444);
    simple.setUpConnection();
    try {
    String result = simple.getResponse("This is first request");
    String result2 = simple.getResponse("This is second request");
    simple.tearDownConnection();
    catch (Exception e) {
    System.out.println("error");
    e.printStackTrace();
    public void setUpConnection() {
    try {
    // Create new socket object
    Socket client = new Socket(host_ip, host_port);
    socketReader = new BufferedReader(new InputStreamReader(client.
    getInputStream()));
    socketWriter = new PrintWriter(client.getOutputStream());
    } catch (UnknownHostException e) {
    System.out.println(
    "Error setting up socket connection: unknown host at " +
    host_ip + ":" + host_port);
    catch (IOException e) {
    System.out.println("Error setting up socket connection: " + e);
    public String getResponse(String request) {
    StringBuffer fileLines = new StringBuffer();
    try {
    socketWriter.println(request);
    socketWriter.flush();
    String line = null;
    int i = 0;
    int chars = 0;
    int sizeOfBuffer = 100;
    char[] cbuf = new char[sizeOfBuffer];
    while ( (chars = socketReader.read(cbuf)) >= 0) {
    fileLines.append(cbuf, 0, chars);
    } catch (Exception e) {
    e.printStackTrace();
    return fileLines.toString();
    public void tearDownConnection() {
    try {
    socketWriter.close();
    socketReader.close();
    } catch (IOException e) {
    System.out.println("Error tearing down socket connection: " + e);
    protected BufferedReader socketReader;
    protected PrintWriter socketWriter;
    protected String host_ip;
    protected int host_port;
    I send two request at the same time.
    Please see code in main method of Simple class
    String result = simple.getResponse("first");
    String result2 = simple.getResponse("second");
    What I think is the socket server will send the same request back to the client.
    So value of result and result2 should be 'first' and 'second'
    But it always return empty String for result2.
    What's the problem?
    Thanks for your help

    Your code has a couple of problems.
    1) the server doesn't flush its socket, so nothing will actually be sent until the socket is closed.
    2) the client getResponse() reads until end of file, so an attempt to use it a second time will fail
    3) in a real application the server should use threads. See the echo server I posted in http://forum.java.sun.com/thread.jsp?forum=11&thread=526980 reply 3.
    Also, please use the [code]  tags when posting source. The lack of these is probaly why you haven't had any repiles until now.

  • Unable to read Password Server response - socket error on socket

    Hi,
    I'm experiencing the following at the OD replica:
    2014-06-03 12:13:06.424616 FET - 592.1446486 - Client: Python, UID: 93, EUID: 93, GID: 93, EGID: 93
    2014-06-03 12:13:06.424616 FET - 592.1446486, Node: /LDAPv3/127.0.0.1, Module: AppleODClientPWS - unable to read Password Server response - socket error on socket fd 12: Resource temporarily unavailable (5205)
    Any ideas are appreciated. Thank you in advance.

    Hi Raja- It seems to be a data quality issue.
    Check for the value @ 1447 position in the xml message that you are trying to send to web service..
    may be a date filed/decimal value which is not in expected format.

  • Java sockets and raw sockets

    Hello!
    I have made my own file sharing program with Java sockets
    and i have read a litle bit about raw sockets also.
    What are the differences between Java sockets and raw sockets?

    raw socket can have packet types which Java does not.
    Generally if you need something useful which Java cannot do there is a utility already written which does what you want, e.g. ping and you can call that.

  • FMS proxying HTTP does not close sockets correctly?

    Hi,
    So, after waiting for a while, we decided to upgrade our streamers to FMS 3.5.3 and set them up to proxy HTTP requests to a lighttpd server instead of the "built in" Apache. With the previous version 3.5 of FMS, we had problems of FMS hanging up after a while and stopping relaying requests, generally a few hours, even when it did not serve a lot of requests. With version 3.5.3, we had great hopes that this problem had disappeared as we had FMS running for more than a month on a test server. So we did the upgrade and we encounter another problem:
    After less that one day of activity, our servers crashed for an unknown reason, almost at the same time. Analysing the logs, I saw out of memory messages, but how could two linux servers stop working in the same 5 minutes interval. I supposed there was a power failure of some sort. And I kept analysing because the sysadmins in the server room swore that they saw out of memory kernel panic on the consoles. After a bit of investigation, I found the reasons: the TCP connexions between FMS and the lighttpd server are stacking up and fill the OS network memory! Now, I don't know who is the culprit:
    FMS code does not manage correctly HTTP proxy sessions?
    lighttpd does not handle correctly HTTP proxying from FMS and does not close correctly the sessions?
    Our Ubuntu linux network stack is not correctly configured to manage so many connexions?
    Here are the details, any assistance is welcome!
    The servers: linux Ubuntu 8.04 with 8 GB RAM.
    FMS 3.5.3 proxying to lighttpd 1.4.19 listening on port 81. FMS and lighttpd are set up on the same server.
    The streamer receives many (> 10/s) HTTP requests from iPhones which are proxied to lighttpd. iPhones request partial content and lighttpd is well suited for these type of requests.
    Locking at the state of the TCP stack:
    # netstat -st
    IcmpMsg:
        InType3: 6
        InType8: 5501
        OutType0: 5501
        OutType3: 6
    Tcp:
        101662 active connections openings
        1192680 passive connection openings
        33 failed connection attempts
        177391 connection resets received
        1653 connections established
        73559682 segments received
        70196072 segments send out
        165137 segments retransmited
        0 bad segments received.
        37219 resets sent
    UdpLite:
    TcpExt:
        22 resets received for embryonic SYN_RECV sockets
        141884 packets pruned from receive queue because of socket buffer overrun
        2052 packets pruned from receive queue
        40293 TCP sockets finished time wait in fast timer
        801 time wait sockets recycled by time stamp
        711318 delayed acks sent
        2401 delayed acks further delayed because of locked socket
        Quick ack mode was activated 535 times
        68554 packets directly queued to recvmsg prequeue.
        11705 bytes directly in process context from backlog
        341070 bytes directly received in process context from prequeue
        5114830 packet headers predicted
        22083 packets header predicted and directly queued to user
        32542120 acknowledgments not containing data payload received
        25289961 predicted acknowledgments
        9191 times recovered from packet loss due to fast retransmit
        6222 times recovered from packet loss by selective acknowledgements
        Detected reordering 7 times using FACK
        Detected reordering 1 times using SACK
        Detected reordering 7 times using reno fast retransmit
        Detected reordering 9 times using time stamp
        15 congestion windows fully recovered without slow start
        42 congestion windows partially recovered using Hoe heuristic
        17 congestion windows recovered without slow start by DSACK
        16517 congestion windows recovered without slow start after partial ack
        51 TCP data loss events
        3916 timeouts after reno fast retransmit
        3372 timeouts after SACK recovery
        10048 timeouts in loss state
        9157 fast retransmits
        6 forward retransmits
        28990 retransmits in slow start
        30176 other TCP timeouts
        7656 classic Reno fast retransmits failed
        95 SACK retransmits failed
        2738020 packets collapsed in receive queue due to low socket buffer
        52 DSACKs sent for old packets
        52 DSACKs received
        3 connections reset due to unexpected data
        74950 connections reset due to early user close
        2846 connections aborted due to timeout
        TCP ran low on memory 10 times
        TCPDSACKIgnoredOld: 41
    IpExt:
    The last red line can be visualised below; sometimes the server crashes in out of memory kernel panic...
    And if you compare with previous behavior, you can tell when we did the upgrade to FMS 3.5.3...
    A few words on our previous configuration with FMS 3.5. To be able to accept HTTP requests, we have a front load balancer which is able to route HTTP requests to lighttpd and RTMP requests to FMS. But with this configuration, we don't benefit from the ability of FMS to fallback to RTMPT for clients behind a proxy or proxy ol' HTTP requests... With the previous configuration, we never had so many connections active simultaneously: we change from 200 max to more than 7000 with FMS 3.5.3 in proxy!
    Some figures on what exactly happens:
    # netstat -tn | grep :81 | awk '{print $6}' | sort | uniq -c
         20 CLOSE_WAIT
       2245 ESTABLISHED
       1236 FIN_WAIT1
          5 TIME_WAIT
    # netstat -tn
    Active Internet connections (w/o servers)
    Proto Recv-Q Send-Q Local Address           Foreign Address         State
    tcp        0 275841 127.0.0.1:81            127.0.0.1:45088         FIN_WAIT1
    tcp   562347      0 127.0.0.1:55150         127.0.0.1:81            ESTABLISHED
    tcp        0 225152 127.0.0.1:81            127.0.0.1:34856         ESTABLISHED
    tcp        0 238081 127.0.0.1:81            127.0.0.1:54310         FIN_WAIT1
    tcp        0 114433 127.0.0.1:81            127.0.0.1:51810         FIN_WAIT1
    tcp   670800      0 127.0.0.1:40746         127.0.0.1:81            ESTABLISHED
    tcp   597444      0 127.0.0.1:40654         127.0.0.1:81            ESTABLISHED
    tcp   592810      0 127.0.0.1:40669         127.0.0.1:81            ESTABLISHED
    tcp        0 103168 127.0.0.1:81            127.0.0.1:54544         ESTABLISHED
    tcp        0 201344 127.0.0.1:81            127.0.0.1:40567         ESTABLISHED
    tcp        0      0 10.1.74.30:1935         10.1.74.2:60372         ESTABLISHED
    tcp   665360      0 127.0.0.1:45282         127.0.0.1:81            ESTABLISHED
    tcp        0 210432 127.0.0.1:81            127.0.0.1:40662         ESTABLISHED
    tcp        0 207361 127.0.0.1:81            127.0.0.1:44895         FIN_WAIT1
    tcp        0 109825 127.0.0.1:81            127.0.0.1:52144         FIN_WAIT1
    tcp        0 221825 127.0.0.1:81            127.0.0.1:54844         FIN_WAIT1
    tcp        0 103168 127.0.0.1:81            127.0.0.1:40791         ESTABLISHED
    tcp   782301      0 127.0.0.1:55074         127.0.0.1:81            ESTABLISHED
    tcp        0 219137 127.0.0.1:81            127.0.0.1:45040         FIN_WAIT1
    tcp        0 209921 127.0.0.1:81            127.0.0.1:44837         FIN_WAIT1
    tcp   574170      0 127.0.0.1:45275         127.0.0.1:81            ESTABLISHED
    tcp        0 252033 127.0.0.1:81            127.0.0.1:54907         FIN_WAIT1
    tcp        0 254977 127.0.0.1:81            127.0.0.1:54515         FIN_WAIT1
    tcp        0 142977 127.0.0.1:81            127.0.0.1:52129         FIN_WAIT1
    In case this is needed, FMS configuration is almost out of the box:
    _defaultRoot_/Adaptor.xml:
    <HTTPTunnel>
                    <Enable>true</Enable>
                    <NodeID></NodeID>
                    <IdlePostInterval>512</IdlePostInterval>
                    <IdleAckInterval>512</IdleAckInterval>
                    <IdleTimeout>60</IdleTimeout>
                    <MimeType>application/x-fcs</MimeType>
                    <WriteBufferSize>16</WriteBufferSize>
                    <SetCookie>true</SetCookie>
                    <Redirect enable="false" maxbuf="16384">
                            <Host port="80">:8080</Host>
                            <Host port="443">:8443</Host>
                    </Redirect>
                    <HttpProxy enable="true" maxbuf="16384">
                            <Host port="80">${HTTPPROXY.HOST}</Host>
                    </HttpProxy>
                    <NeedClose>true</NeedClose>
                    <MaxWriteDelay>20</MaxWriteDelay>
                    <MinWriteDelay>12</MinWriteDelay>
                    <MaxHeaderLineLength>1024</MaxHeaderLineLength>
    </HTTPTunnel>
    I've tried changing lighttpd configuration to handle KeepAlive session or not, it has no influence on the behaviour.
    If you spot a configuration mistake or have any idea, I'm ready to test it as soon as possible... Asa?
    Thanks

    Has this been fixed? What was done?
    We have been having the same issue. We worked on it with Adobe support and thought it might have been fixed with a "patched" version of FMS that was created to solve the problem. However, we still see the issue (recently we had a huge increase in load due to an annual event).
    Over time, when we run netstat, we see Apache connections (127.0.0.1:88134) stuck in a FIN_WAIT_1 state while the corresponding FMS processes (127.0.0.1:1025 to 5000) are in an ESTABLISHED state. It appears as though the connection is closed from the http proxy side while FMS doesn't acknowledge the close.
    We notice this behavior seems related to load. High load = connections getting hung more frequently. The only fix seems to be restarting the FMS service which restarts the embedded apache as well.
    I'm curious if you found a fix or even a workaround to help you cope with these connections. Even something to close them periodically would be a huge help. So far, we're resorting to an automatic restart of the server ever 2 days which is hardly a proper production solution.
    I would really appreciate any information you could provide with regards to your particular problem and whether or not it's been solved.
    An example (just a snippet) of the netstat monitor we have running each hour on the half-hour:
      Proto  Local Address          Foreign Address        State
      <snip FMS to Apache>
      TCP    127.0.0.1:2847         127.0.0.1:8134         ESTABLISHED
      TCP    127.0.0.1:2848         127.0.0.1:8134         ESTABLISHED
      TCP    127.0.0.1:2849         127.0.0.1:8134         ESTABLISHED
      TCP    127.0.0.1:2850         127.0.0.1:8134         ESTABLISHED
      TCP    127.0.0.1:2851         127.0.0.1:8134         ESTABLISHED
      TCP    127.0.0.1:2853         127.0.0.1:8134         ESTABLISHED
      TCP    127.0.0.1:2854         127.0.0.1:8134         ESTABLISHED
      TCP    127.0.0.1:2855         127.0.0.1:8134         ESTABLISHED
      TCP    127.0.0.1:2856         127.0.0.1:8134         ESTABLISHED
      TCP    127.0.0.1:2857         127.0.0.1:8134         ESTABLISHED
      TCP    127.0.0.1:2858         127.0.0.1:8134         ESTABLISHED
      TCP    127.0.0.1:2859         127.0.0.1:8134         ESTABLISHED
      TCP    127.0.0.1:2860         127.0.0.1:8134         ESTABLISHED
      TCP    127.0.0.1:2861         127.0.0.1:8134         ESTABLISHED
      TCP    127.0.0.1:2862         127.0.0.1:8134         ESTABLISHED
      TCP    127.0.0.1:2863         127.0.0.1:8134         ESTABLISHED
      TCP    127.0.0.1:2864         127.0.0.1:8134         ESTABLISHED
      TCP    127.0.0.1:2865         127.0.0.1:8134         ESTABLISHED
      TCP    127.0.0.1:2866         127.0.0.1:8134         ESTABLISHED
      TCP    127.0.0.1:2867         127.0.0.1:8134         ESTABLISHED
      TCP    127.0.0.1:2868         127.0.0.1:8134         ESTABLISHED
      </snip FMS to Apache>
      <snip Apache to FMS (corresponding entries)>
      TCP    127.0.0.1:8134         127.0.0.1:2847         FIN_WAIT_1
      TCP    127.0.0.1:8134         127.0.0.1:2848         FIN_WAIT_1
      TCP    127.0.0.1:8134         127.0.0.1:2849         FIN_WAIT_1
      TCP    127.0.0.1:8134         127.0.0.1:2850         FIN_WAIT_1
      TCP    127.0.0.1:8134         127.0.0.1:2851         FIN_WAIT_1
      TCP    127.0.0.1:8134         127.0.0.1:2853         FIN_WAIT_1
      TCP    127.0.0.1:8134         127.0.0.1:2854         FIN_WAIT_1
      TCP    127.0.0.1:8134         127.0.0.1:2855         FIN_WAIT_1
      TCP    127.0.0.1:8134         127.0.0.1:2856         FIN_WAIT_1
      TCP    127.0.0.1:8134         127.0.0.1:2857         FIN_WAIT_1
      TCP    127.0.0.1:8134         127.0.0.1:2858         FIN_WAIT_1
      TCP    127.0.0.1:8134         127.0.0.1:2859         FIN_WAIT_1
      TCP    127.0.0.1:8134         127.0.0.1:2860         FIN_WAIT_1
      TCP    127.0.0.1:8134         127.0.0.1:2861         FIN_WAIT_1
      TCP    127.0.0.1:8134         127.0.0.1:2862         FIN_WAIT_1
      TCP    127.0.0.1:8134         127.0.0.1:2863         FIN_WAIT_1
      TCP    127.0.0.1:8134         127.0.0.1:2864         FIN_WAIT_1
      TCP    127.0.0.1:8134         127.0.0.1:2865         FIN_WAIT_1
      TCP    127.0.0.1:8134         127.0.0.1:2866         FIN_WAIT_1
      TCP    127.0.0.1:8134         127.0.0.1:2867         FIN_WAIT_1
      TCP    127.0.0.1:8134         127.0.0.1:2868         FIN_WAIT_1
      </snip Apache to FMS>
    This particular log shows all ports between 1024 and 5000 in the same state as above. A restart resets all the connections and the process starts over. From my investigation, Apache seems to be acting properly. It tries to be a 'good citizen' and issue a graceful close that goes unacknowledged by FMS. Unfortunately, Apache doesn't go back to check a connection it considers closed, so they connection remains half-closed.
    Please, please let me know if you found anything out. Information on the web is scarce and I'm at my wit's end!

  • How to close socket, if attempting to accpet clients?

    How do I close the socket if .accept is attempting to try to accept clients:
    //Wait for the acceptance from a client
    clientSocket = serverSocket.accept();
    //In the main thread: User wants to disconnect from chat room
    try{clientSocket.close();}catch(Exception e){ }
    //this is dis-allowed, and throws an exception, how can i get around this?

    After who (client or server) closes what socket? and tries to reconnect what?
    If you close the ServerSocket, future connects will fail.
    If you close the client (accepted) socket, the client will read an EOS condition.
    If you try to open a new ServerSocket on the same port without closing the old one, you will get a BindException.
    As I have no idea what you're actually doing I can't help any further. Post the (reduced to minimal) code and the stack trace, and show which line of code is incurring the exception.

  • Close socket on closing window in JSP.

    Hi,
    I want to send a command to the backend server from my webserver to close the socket connection when the user closes the window. can any one help how to determine when a window is closed in JSP.
    Thank you.

    I'm presuming you have a login, and on that successful login, you start this socket thing and put some reference in the session.
    So what you do, no matter what else, is have this reference object that holds the socket or whatever implement HttpSessionBindingListener. And for that interface, you implement the valueUnbound() method so that when the item is removed from the session, it'll close the socket and do whatever other clean up.
    This will always be invoked then when the session is invalidated, either by session timeout or by explicit log out (which should explicitly call session.invalidate()).
    Then, if you decide to try to overlay some extra thing on your web site to try to catch the user leaving the site or exiting the browser, if it works, great. If not, you're still covered.

  • Can a socket connection be created inside a Timeline to port 23?

    Is there a security restriction or some other reason why I always get a java.net.ConnectException: Connection refused at java.net.PlainSocketImpl.socketConnect(Native Method)
    when I try to open a socket inside a function in a Timeline to port 23? The connection works fine to the host if the code is not is not inside a Timeline. It also seems that a socket connection to port 80 works okay too.
    Thanks for any help in advance.
    Regards,
    Richard

    Here is the Timeline code:
    var addr:InetSocketAddress;
    var sConn:Socket;
    var reader:BufferedReader;
    var s:String;
    Timeline {
    repeatCount: Timeline.INDEFINITE
    keyFrames: [
    KeyFrame {
    time: 10s
    action: function() {
    try {
    addr = new InetSocketAddress("somehost",23);
    sConn = new Socket();
    sConn.connect(addr);
    reader = new BufferedReader(
    new InputStreamReader(sConn.getInputStream()));
    // reader.readLine(); // throw away first line
    s = reader.readLine();
    bindTemp = response.getResponse("$0001").getTemperature();
    bindVolt = response.getResponse("$0001").getVoltage();
    } catch (e:Exception) {
    System.err.println(e);
    }.play();
    The ConnectionRefused error occurs only when the NetBeans Project Application Properties "Draggable Applet" checkbox is checked ( which is the default ). Once I uncheck it, the error goes away.
    -Richard

  • Two Socket errors: Socket write and Socket reset

    does anyone know the reasons and remedies for the error
    java.net.SocketException: Software caused connection abort: socket write error
    and
    java.net.SocketException: Connection reset by peer: socket write error
    please reply if someone knows
    thanks

    These are basically the same error triggered in different places.
    This occurs when the other end of the connection closes while the client is still writing to it.

  • Im Stuck, error in my server (j2se socket) with j2me (socket)

    I dunt understand, previous worked, now (2.3beta wireless toolkit) doenst work anymore, u guys can help me?
    SERVER CODE J2SE
    package com.pc.jwolf.server.testes;
    import java.io.DataInputStream;
    import java.io.DataOutputStream;
    import java.io.IOException;
    import java.net.ServerSocket;
    import java.net.Socket;
    public class Teste01 {
         public Teste01() throws IOException {
              ServerSocket s = new ServerSocket(3131);
              Socket sx = s.accept();
              DataInputStream input = new DataInputStream(sx.getInputStream());
              DataOutputStream output = new DataOutputStream(sx.getOutputStream());
              output.flush();
              int c = 0;
              StringBuffer b = new StringBuffer();
              while((c=input.read()) != -1) b.append((char) c);
              System.out.println(new String(b));
         public static void main(String[] args) {
              try {
                   new Teste01();
              } catch (IOException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
    }MOBILE CODE (J2ME) CLDC 1.1 Profile 2.0
    import java.io.DataInputStream;
    import java.io.DataOutputStream;
    import javax.microedition.io.Connector;
    import javax.microedition.io.SocketConnection;
    import javax.microedition.midlet.MIDlet;
    import javax.microedition.midlet.MIDletStateChangeException;
    public class Midlet extends MIDlet {
         protected void startApp() throws MIDletStateChangeException {
              // TODO Auto-generated method stub
              try {
                   SocketConnection sc = (SocketConnection) Connector
                             .open("socket://127.0.0.1:3131");
                   DataInputStream input = sc.openDataInputStream();
                   DataOutputStream out = sc.openDataOutputStream();
                   out.flush();
                   out.writeUTF("HELLO WORLD!!!!!!");
                   out.flush();
              } catch (Exception e) {
                   // TODO: handle exception
                   e.printStackTrace();
         protected void pauseApp() {
              // TODO Auto-generated method stub
         protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
              // TODO Auto-generated method stub
    }My server cant read the message... whats wrong?
    Tkz.

    Hi,
    I the exact same problem. I didn't quite understand what you meant by closing the socket. When i close the socket on the server side before I enter the whole look it throws an exception. Could please help out and maybe paste a little code to explain further.
    Thank you

  • Open and close visa inside a while loop

    Hi,
    I need to read a position from a control unit device continuously or even by click a button, for this I have to put "visa configure serial port" and" "visa close" inside a while loop. Dose it make any problem?

    You shouldn't need the VISA Event nodes.  Get rid of those.
    Why are you using Concatinate String just to build up a constant.  Just create a single string constant.  It is a lot cleaner.
    Is the antenna constantly sending data to you or only when you request it?
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • Dynamic attributes inside JVM

    Is there anyone knows if from inside an oject I can take some information about an object loaded in JVM?
    I want this information to be the same for an object independently of the machine or platform it is used, and somebody will not be able to obtain this information by statically analyzing the code.
    This way this information cannot be leaked to anybody except this object. Thus if somebody will slightly change the class to print this information the desired information will have changed.
    Best Regards,
    Haris

    Hi Gregory,
    It's known issue.
    I don't know exact patch for this but you can patch it:
    1. Unpack the sap.com_cafUIdynattr~admin.sda archive from sca.
    2. Unpack sap.comcafUIdynattradmin.wda archive.
    3. Open the PORTAL-INF\portalapp.xml file and the following entry to SharingReference section:
    <property name="SharingReference"    value="sap.com/cafUIptn~common"/>
    And pack it again in correct order(for ex.:
    jar.exe -Mcvf sap.comcafUIdynattradmin.wda .
    jar.exe -Mcvf sap.com_cafUIdynattr~admin.sda .
    Best regards,
    Aliaksei

Maybe you are looking for