how to make sure Socket has connected?
-
Hi all, I would like to be able to correctly determine whether I have connected to my Host before trying to login. Everything I can think of trying has failed. If I try connecting to 192.168.0.1 110 it says its connected, but has 0 bytes Available. Which is great, and works for valid and invalid addresses whilst debugging, but as soon as I remove all breakpoints it comes back with errors on the valid addresses. I done a quick search, and found using a mixture of Poll and Available which unfortunately doesn't work either. Basically I don't want any code to continue until I have a Connected and Communicating Socket. Any idea's? Regards Gav
-
Hi all, I would like to be able to correctly determine whether I have connected to my Host before trying to login. Everything I can think of trying has failed. If I try connecting to 192.168.0.1 110 it says its connected, but has 0 bytes Available. Which is great, and works for valid and invalid addresses whilst debugging, but as soon as I remove all breakpoints it comes back with errors on the valid addresses. I done a quick search, and found using a mixture of Poll and Available which unfortunately doesn't work either. Basically I don't want any code to continue until I have a Connected and Communicating Socket. Any idea's? Regards Gav
Gavin Roberts wrote:
it comes back with errors
What errors? What "comes back with errors"?
Gavin Roberts wrote:
Basically I don't want any code to continue until I have a Connected and Communicating Socket.
Then check for the error and if present don't continue
-
Gavin Roberts wrote:
it comes back with errors
What errors? What "comes back with errors"?
Gavin Roberts wrote:
Basically I don't want any code to continue until I have a Connected and Communicating Socket.
Then check for the error and if present don't continue
Sorry. Basically I use Socket.Available to check if any data is available before continuing which whilst stepping through with a debugger, works fine as soon as I run the code with no breakpoints Socket.Available returns 0. I am currently using Socket.Read to check but that is quite slow. Cheers for the reply. Gav
-
Sorry. Basically I use Socket.Available to check if any data is available before continuing which whilst stepping through with a debugger, works fine as soon as I run the code with no breakpoints Socket.Available returns 0. I am currently using Socket.Read to check but that is quite slow. Cheers for the reply. Gav
Gavin Roberts wrote:
I am currently using Socket.Read to check but that is quite slow.
Slow?? Read will read quit fast when the TCP/IP stack has received the data from the remote socket. If it is "slow" then the network connection or remote server must be slow. Under normal network and server conditions for a POP3 Server, you can do a blocking "Connect" and when that returns you can "Read" the "OK" message sent by the Server immediately. There should be no significant delay. If there is, then you have a network issue or the POP3 Server is slow.
-
Gavin Roberts wrote:
I am currently using Socket.Read to check but that is quite slow.
Slow?? Read will read quit fast when the TCP/IP stack has received the data from the remote socket. If it is "slow" then the network connection or remote server must be slow. Under normal network and server conditions for a POP3 Server, you can do a blocking "Connect" and when that returns you can "Read" the "OK" message sent by the Server immediately. There should be no significant delay. If there is, then you have a network issue or the POP3 Server is slow.
I am using Socket.Connect to connect. At the moment, I am having to use Socket.Receive to determine whether the connection is valid or not. I was using Socket.Available, but this only seemed to work when I was stepping through each line using Visual Studio. As soon as I removed all breakpoints and allowed it to continue as normal, Socket.Available returned incorrect data, as if it hadn't enough time to populate. Socket.Receive is slow for a invalid Connection, and i'd prefere to speed this up. Thanks Gav
-
I am using Socket.Connect to connect. At the moment, I am having to use Socket.Receive to determine whether the connection is valid or not. I was using Socket.Available, but this only seemed to work when I was stepping through each line using Visual Studio. As soon as I removed all breakpoints and allowed it to continue as normal, Socket.Available returned incorrect data, as if it hadn't enough time to populate. Socket.Receive is slow for a invalid Connection, and i'd prefere to speed this up. Thanks Gav
Gavin Roberts wrote:
Socket.Receive is slow for a invalid Connection, and i'd prefere to speed this up.
Socket.Receive is blocking which means that it will only return after it has received data or the connection has been closed. To check if the connection is valid you will have to look at the socket options available to see if any of those help. Also you should be checking the return status of Socket.Connect to see if it connected properly and if you are not catching any exceptions around the Socket.Connect, then you will be missing information that may lead to the answer you are seeking. An inference from the above is that the socket should be valid by the time the receive method is called. Phil
-
I am using Socket.Connect to connect. At the moment, I am having to use Socket.Receive to determine whether the connection is valid or not. I was using Socket.Available, but this only seemed to work when I was stepping through each line using Visual Studio. As soon as I removed all breakpoints and allowed it to continue as normal, Socket.Available returned incorrect data, as if it hadn't enough time to populate. Socket.Receive is slow for a invalid Connection, and i'd prefere to speed this up. Thanks Gav