Solved

Winsock experts....

Posted on 2002-07-17
17
372 Views
Last Modified: 2013-11-13

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.
0
Comment
Question by:sanjaykattimani
  • 9
  • 5
  • 2
  • +1
17 Comments
 
LVL 4

Expert Comment

by:RichW
ID: 7160046
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.









0
 
LVL 2

Expert Comment

by:brookman
ID: 7160338
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.




0
 
LVL 3

Author Comment

by:sanjaykattimani
ID: 7161833
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?

0
 
LVL 2

Expert Comment

by:brookman
ID: 7162229
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
0
 
LVL 3

Author Comment

by:sanjaykattimani
ID: 7164069
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.
0
 
LVL 3

Expert Comment

by:PNJ
ID: 7164409
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.
0
 
LVL 3

Author Comment

by:sanjaykattimani
ID: 7164424
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.



0
 
LVL 3

Expert Comment

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

Pete
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 3

Author Comment

by:sanjaykattimani
ID: 7164562
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....................
0
 
LVL 2

Expert Comment

by:brookman
ID: 7164862
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

0
 
LVL 3

Author Comment

by:sanjaykattimani
ID: 7164882
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.
0
 
LVL 2

Expert Comment

by:brookman
ID: 7164895
So you are telling me even after a disconnect you get a result from

winsock1(?).state that returns a 7

0
 
LVL 3

Author Comment

by:sanjaykattimani
ID: 7165328
Yes Exactly 7. So i'll never know whether its restarted [restart button pressed].
0
 
LVL 2

Accepted Solution

by:
brookman earned 130 total points
ID: 7166030
How about writing a heartbeat routine.  If the socket is not in a listen state send a character to each connection and have your clients answer -

no answer = no connection

then reset the port
0
 
LVL 3

Author Comment

by:sanjaykattimani
ID: 7166473
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..]
0
 
LVL 3

Author Comment

by:sanjaykattimani
ID: 7168666
Isnt it possible to know the status without Heart beat routine???
0
 
LVL 3

Author Comment

by:sanjaykattimani
ID: 7190131
I implemented heart beat routine which is working fine. Thanks for the ideas.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now