Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Oct 4th, 2006, 11:30 PM   #1
hoffmandirt
Hobbyist Programmer
 
hoffmandirt's Avatar
 
Join Date: Jul 2005
Location: PA
Posts: 125
Rep Power: 4 hoffmandirt is on a distinguished road
Send a message via AIM to hoffmandirt
Determine when client socket request has been accepted.

How can it be determined when a connection request sent by a client socket has been accepted by the server socket vs. the request just sitting in the ServerSocket connection request queue awaiting to be accepted?
hoffmandirt is offline   Reply With Quote
Old Oct 5th, 2006, 10:02 AM   #2
jaeusm
Programmer
 
jaeusm's Avatar
 
Join Date: Feb 2006
Location: Columbus, OH
Posts: 84
Rep Power: 3 jaeusm is on a distinguished road
Why would you want to know this? I would assume that the creation of the client's socket would not return until the ServerSocket has 'accepted' the request, though the Java APIs don't explicitly specify this.
jaeusm is offline   Reply With Quote
Old Oct 5th, 2006, 10:10 AM   #3
hoffmandirt
Hobbyist Programmer
 
hoffmandirt's Avatar
 
Join Date: Jul 2005
Location: PA
Posts: 125
Rep Power: 4 hoffmandirt is on a distinguished road
Send a message via AIM to hoffmandirt
That's not true. The server socket has a queue that stores connection requests. When you call the accept method, it blocks until there is a connection request in the server socket queue. Creation of the socket on the client side only blocks until it gets put in the server sockets request queue you cannot use this socket for communication until it is accepted however.
hoffmandirt is offline   Reply With Quote
Old Oct 5th, 2006, 10:33 AM   #4
jaeusm
Programmer
 
jaeusm's Avatar
 
Join Date: Feb 2006
Location: Columbus, OH
Posts: 84
Rep Power: 3 jaeusm is on a distinguished road
Yes, I know, but you've misunderstood me. When I say
Quote:
creation of the client's socket would not return until the ServerSocket has 'accepted' the request
I mean that the client Socket will not return from the constructor call until it has been accepted by the ServerSocket, including the time it sits in the queue. Again, this is speculation since it isn't specified in the Socket or ServerSocket APIs.

Quote:
Creation of the socket on the client side only blocks until it gets put in the server sockets request queue
Where did you get this information?

Last edited by jaeusm; Oct 5th, 2006 at 10:48 AM.
jaeusm is offline   Reply With Quote
Old Oct 5th, 2006, 10:52 AM   #5
hoffmandirt
Hobbyist Programmer
 
hoffmandirt's Avatar
 
Join Date: Jul 2005
Location: PA
Posts: 125
Rep Power: 4 hoffmandirt is on a distinguished road
Send a message via AIM to hoffmandirt
I did understand you and that is what I am saying. The call returns from the constructor as soon as it sends the request and finds the server socket waiting for connection requests. When you start a server socket, it is sitting there waiting for requests. It stores these requests in a queue. Then when you call the accept method, it pulls the request out of the queue and returns a Socket. Try it out, start a server socket, but do not call the accept method, but instead open multiple client sockets.
hoffmandirt is offline   Reply With Quote
Old Oct 5th, 2006, 11:19 AM   #6
jaeusm
Programmer
 
jaeusm's Avatar
 
Join Date: Feb 2006
Location: Columbus, OH
Posts: 84
Rep Power: 3 jaeusm is on a distinguished road
You are correct. However, I started using the client socket before it was accepted by sending a simple message. The ServerSocket apparently queues the message and responds after it accepts the request. So it appears that you can "use" a socket while it is queued.
jaeusm is offline   Reply With Quote
Old Oct 5th, 2006, 12:22 PM   #7
hoffmandirt
Hobbyist Programmer
 
hoffmandirt's Avatar
 
Join Date: Jul 2005
Location: PA
Posts: 125
Rep Power: 4 hoffmandirt is on a distinguished road
Send a message via AIM to hoffmandirt
I decided to set a timeout on the client socket and if the read times out, then reconnect. I ran into this problem having top laptop's with each one connected to a bridge and when the wireless signal went down, I could no longer depend on the client socket to throw an io exception. I was doing some reading and it seems that it is just a good idea to set a timeout on these things.
hoffmandirt is offline   Reply With Quote
Old Oct 5th, 2006, 5:22 PM   #8
Harakim
Hobbyist Programmer
 
Join Date: May 2006
Location: West Jordan, Utah, United States
Posts: 176
Rep Power: 3 Harakim is on a distinguished road
I think you should be using SocketChannels in the stead of Sockets.

In response to your question, if it "connects" without accepting the connection, you can't determine when it has been accepted from the client side.
Harakim is offline   Reply With Quote
Old Oct 6th, 2006, 9:50 AM   #9
hoffmandirt
Hobbyist Programmer
 
hoffmandirt's Avatar
 
Join Date: Jul 2005
Location: PA
Posts: 125
Rep Power: 4 hoffmandirt is on a distinguished road
Send a message via AIM to hoffmandirt
Right, so i put a timeout on the read from the client side, which will attempt to reconnect. I do not know much about socket channels, I will look in to them, but can you tell me why they would be better?
hoffmandirt is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Java socket Server compile errors.. n3o_X Java 3 Nov 18th, 2007 12:39 AM
Python FTP Client Wrapper Sane Python 6 Jun 22nd, 2006 9:44 PM
how to check if the socket is still connected? myName C++ 1 Jun 14th, 2006 6:27 AM
Socket Server hbe02 C++ 19 May 23rd, 2006 10:14 PM
Instant Messaging App Help AusTex C 0 Apr 27th, 2005 4:52 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:58 PM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC