Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Socket Problem

  1. #1
    Member
    Join Date
    Jan 2011
    Posts
    88
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Question Socket Problem

    Hello everyone, I am working on a server and client pair and they connect just fine my problem is that the server needs to detect when the client disconnects. Right not I am using

    socket.isConnected()

    and also I am creating a dataoutput stream and writting the int 700 to it. If the output stream returns an error or isConnected returns false it is supposed to kick that client off of the server.

    This is were the problem begins. If the clients computer is shut down or the process is ended then this works perfectly fine but if the client computer goes to sleep the server doesnt detect that the client is no longer connected and when the computer wakes up there is no connection or a new one is established.

    Is there anyway that I can detect if the computer is going to sleep client sided and close the socket from there or any other ways to see if the client is still connected?


  2. #2
    Junior Member
    Join Date
    Oct 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Socket Problem

    socket.accept() this menthos for using SocketServer is Accept for come client accept. Print Message using for host name get to connect the clinet name for using server side accept method next line.

  3. #3
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Socket Problem

    Quote Originally Posted by Jeevaraj View Post
    socket.accept() this menthos for using SocketServer is Accept for come client accept. Print Message using for host name get to connect the clinet name for using server side accept method next line.
    Huh???? That makes no sense.

    Is there anyway that I can detect if the computer is going to sleep client sided and close the socket from there or any other ways to see if the client is still connected?
    How about having the client timeout after a certain duration of activity? You could do this server side, where the server disconnects the client if no communication between the two occurs after a certain specified duration

  4. #4
    Member
    Join Date
    Jun 2012
    Posts
    41
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Socket Problem

    As copeg said, timeout is probably the way to go. There is a reason timeout was invented, and that's because there's not many other options. If you're not already, you will have to multi-thread things, because your thread doing communication could block (especially when your clients could be inactive) which is fine, as long as EVERYTHING ELSE is not on the same thread.

Similar Threads

  1. Socket Problem?
    By danza in forum What's Wrong With My Code?
    Replies: 0
    Last Post: June 10th, 2012, 02:22 AM
  2. Java socket server problem
    By Lionlev in forum Java Networking
    Replies: 6
    Last Post: May 27th, 2012, 11:22 AM
  3. Socket problem
    By Robtn in forum What's Wrong With My Code?
    Replies: 11
    Last Post: June 15th, 2011, 03:50 PM
  4. [SOLVED] Problem in socket programming
    By sinni in forum Java Networking
    Replies: 1
    Last Post: March 15th, 2011, 10:26 AM
  5. [SOLVED] Socket Programming Problem
    By relixus in forum What's Wrong With My Code?
    Replies: 7
    Last Post: December 9th, 2010, 10:35 PM

Tags for this Thread