![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Hobbyist Programmer
|
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?
|
|
|
|
|
|
#2 |
|
Programmer
Join Date: Feb 2006
Location: Columbus, OH
Posts: 84
Rep Power: 3
![]() |
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.
|
|
|
|
|
|
#3 |
|
Hobbyist Programmer
|
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.
|
|
|
|
|
|
#4 | ||
|
Programmer
Join Date: Feb 2006
Location: Columbus, OH
Posts: 84
Rep Power: 3
![]() |
Yes, I know, but you've misunderstood me. When I say
Quote:
Quote:
Last edited by jaeusm; Oct 5th, 2006 at 10:48 AM. |
||
|
|
|
|
|
#5 |
|
Hobbyist Programmer
|
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.
|
|
|
|
|
|
#6 |
|
Programmer
Join Date: Feb 2006
Location: Columbus, OH
Posts: 84
Rep Power: 3
![]() |
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.
|
|
|
|
|
|
#7 |
|
Hobbyist Programmer
|
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.
|
|
|
|
|
|
#8 |
|
Hobbyist Programmer
Join Date: May 2006
Location: West Jordan, Utah, United States
Posts: 176
Rep Power: 3
![]() |
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. |
|
|
|
|
|
#9 |
|
Hobbyist Programmer
|
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?
|
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|
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 |