Link to home
Start Free TrialLog in
Avatar of sanjaykattimani
sanjaykattimani

asked on

Winsock experts....


I have been using winsock controls from last 6 months but still unable to solve this problem completely. Here it goes..
I have an array of winsock controls on server which keeps listening for a connection. Then workstations are there which connects to the server then the interaction starts. There is no problem with the interaction. its perfect as long as the connection exists.
Problem starts when one of the connected workstation restarts. Server shows the status as connected [state property of winsock] where as the workstation is restarting. In this state it will not allow any connection on the same port as its already connected. So workstation after restart cannot connect to the workstation.

I have another application installed [just the exe file, not the source] which uses winsock and gets the restart status perfectly. It was also developed in vb and runs on win98 [same as in my case] Hence i assume that its possible.

Thanks in advance.
Avatar of RichW
RichW
Flag of United States of America image

Only one accepted connection will be made. Use the Listen method to accept more.

The Listen method creates a socket and sets it in listen mode. This method works only for TCP connections.









Avatar of brookman
brookman

You will have to modify this to work with your control array but...


Private Sub Timer1_Timer()
Text1.Text = Winsock1.State
End Sub

this will tell the current state of the particular winsock control.

If you see a disconnect or invalid stat you can reset this paricular port.




Avatar of sanjaykattimani

ASKER

TO RichW
>Only one accepted connection will be made. Use the Listen method to accept more.
Its already doing the same, and as far as connection is concerned there is no problem with existing connection.

>The Listen method creates a socket and sets it in listen mode. This method works only for TCP connections.
I am using tcp ip protocol only in winsock.


To BrookMan
I am doing exactly the same. Infact i wrote some code just to check the status of winsocks array. I connected few workstations to server and checked the status all of them showed status as connected [7] - For this is used a log file and it writes the current status to a text file whenever i click a check status button. Then i restarted one of the workstation and checked the status again. This time i was expecting one of the connection status to be some thing other than connected. But it wasnt. All of them showed status as connected.
Server never tries to send anything till workstations request for some info or data. So server never sends anything by itself through some timer control or anything like that.
Now is it not possible to get the connected status perfectly just with state property? How do i get to know that the workstation is restarted?

I am using the following in my program in the dataarrived section of the winsock control:

Form3.Winsock1(k).State <> sckClosed

I did a bunch of hangups and the state of the port was reflected as sckClosed (0).

this is the actual monitor routine in timer1

For k = 0 To 5
v = Winsock1(k).State
Select Case v
Case 0
Text1(k).Text = "Not Connected"
Case 1
Text1(k).Text = "Connection Open"
Case 2
Text1(k).Text = "Listening"
Case 3
Text1(k).Text = "Connection Pending"
Case 4
Text1(k).Text = "Resolving Host"
Case 5
Text1(k).Text = "Host Resolved"
Case 6
Text1(k).Text = "Connecting"
Case 7

Text1(k).Text = "Connected"


Case 8
Text1(k).Text = "Peer is closing connection"
Winsock1(k).Close

Case 9
Text1(k).Text = "Error"
End Select
Text1(k).Text = Text1(k).Text & "  " & Winsock1(k).RemoteHost & ":" & Winsock1(k).RemotePort & "   " & simname(k)


Next k
End Sub
To Brookman
Thanks for the response.
I already hav a routine like this in my server.

>I am using the following in my program in the dataarrived section of the winsock control:
Form3.Winsock1(k).State <> sckClosed
I did a bunch of hangups and the state of the port was reflected as sckClosed (0).

Would you please elaborate what are those hangups[if winsock related] which closes the port if connected workstation is restarted? This is exactly what i want-server to know that port is closed.

As i mentioned earlier also, i always get the port status as connected. so i cant take any action on that.
I think I follow. The server socket will release the port after a timeout of about 2 minutes. I think the problem is at the client end. Try setting "sckClient.LocalPort=0", the force the control to choose another (unused) random port.
TO PNJ
>The server socket will release the port after a timeout of about 2 minutes. I think the problem is at the client end. Try setting "sckClient.LocalPort=0", the force the control to choose another (unused) random port.

I dont want workstation to connect to any random port but to connect to some predefined ports. So far i havent mentioned localport to any winsocks and they are at their default value.



I accept your comment, but have a look at this link: http://support.microsoft.com/default.aspx?scid=kb;EN-US;q173619

Pete
To PNJ

This again is not a problem, from workstation side, there is no problem. Its connecting as soon as the port if free. Server is unable to get the actual connected status when workstation restarts.

Oh god.....Please send some one down to earth with the solution....................
Is your winsock array listening on a bunch of different ports or is it one at a time?

if you are listening on a bunch of different ports you can
use this in the timer section.

if Winsock1(k).State <> sckClosed then
winsock1(k).listen
endif

TO Brookman.
I am doing the same and there is no problem if i get to know that a winsock is closed.
As i have been saying when workstation gets restarted in server that workstation's winsock status still says its connected. When it says it is still connected i cannot again listen on the same port.
So you are telling me even after a disconnect you get a result from

winsock1(?).state that returns a 7

Yes Exactly 7. So i'll never know whether its restarted [restart button pressed].
ASKER CERTIFIED SOLUTION
Avatar of brookman
brookman

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I have been thinking about this since the begining of this problem. But there are a few things that i have been thinking which stopped me implementing this. Here are those

1) I will having 5-25 winsocks on the server where workstations get connected.
2) Since this is an array of winsocks, all 25 connected workstation's data will be processed [processing the requests of ws] from the same routine, so i hav to make sure its not over burdened.
3) Adding this heart beat routine will even more burden dataArrival

Keeping these things in mind, suggest me whether i should go for heart beat routine or not.
If i get the status as soon as i get i wont have any problem. [Sigh..]
Isnt it possible to know the status without Heart beat routine???
I implemented heart beat routine which is working fine. Thanks for the ideas.