|
-
Mar 29th, 2011, 04:06 PM
#1
Thread Starter
Junior Member
Winsock state not changing
This is my first Winsock project.
I want to check if my connection the connected device (192.168.0.160) is alive.
So I made the following code:
Code:
Private Sub Form_Load()
If Winsock1.State <> sckConnected Then
Winsock1.RemoteHost = "192.168.0.160"
Winsock1.RemotePort = "10055"
Winsock1.Connect
End If
Timer1.Interval = 500
End Sub
Private Sub Form_Unload(Cancel As Integer)
Winsock1.Close
End Sub
Private Sub Timer1_Timer()
Select Case Winsock1.State
Case 6
Debug.Print "sckConnecting"
Case 7
Debug.Print "sckConnected"
End Select
End Sub
Nothing fancy
But now the problem:
if my device is off and start my program, the winsock state is 6 ("sckConnecting") => no problem
Then I turn on my device and the winsock state changes to 7 ("sckConnected") => still no problem.
But if I then turn off my device (of disconnect the LAN connector) the winsock state will stay 7 ("sckConnected")
Why is it not changing back to 6 ("sckConnecting")??
Kiter
-
Mar 29th, 2011, 05:54 PM
#2
Re: Winsock state not changing
Have you enabled the timer?
Edit:
This might be useful.
Last edited by Nightwalker83; Mar 29th, 2011 at 06:04 PM.
Reason: Adding more!
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
Mar 30th, 2011, 12:42 AM
#3
Re: Winsock state not changing
 Originally Posted by Kiter
Why is it not changing back to 6 ("sckConnecting")??
Because as far as it's concerned it's still connected. When your device shuts down it will trigger the Winsock_Close event in your program. It's up to you to recognise that event, close the socket and then try to re-connect
Code:
Private Sub Winsock1_Close()
'
' Server has closed the connection
' Close our socket and attempt to reconnect
'
Winsock1.Close
Winsock1.Connect
End Sub
-
Mar 30th, 2011, 04:41 AM
#4
Re: Winsock state not changing
Disconnecting the LAN adapter does not close the connection. This is intentional.
A TCP connection is a software concept, it has nothing to do with an electrical connection. There are system timeouts and retries that must expire before a disconnect is signaled, and these add up to as much as 4 minutes (perhaps an average of 2 minutes) before a disconnect will be signaled back to your program.
This allows TCP connections to operate without error even though momentary interruptions may occur end-to-end.
This is entirely different from an explicit close action, which sends a specific kind of control packet to the other end. Both ends must do a close in order to achieve a normal disconnect. Just orphaning a connection by terminating the program at one end is again subject to timeouts and retries.
There is a non-standardized "keep alive" mechanism in some TCP implementations. The timeouts and retries associated with that normally add up to around 2 hours though.
As you can see these are very long times indeed. Shortening the timers and retry counters is discouraged, and in some cases has to be done at the OS level (globally). The reason is that these are infrastructure timeouts meant to be used by gateways (routers) and not by applications on a connection by connection basis. Shortening the timeout intervals also produces a great deal of wasted network bandwidth polling for current status.
In rare cases it may be important, and in those cases you must implement application keepalives as part of your application protocol. Even then you should keep the intervals pretty long between probes or you'll just tie up the "pipe" with pointless chatter that steals bandwidth from everyone else using any network in the path between you and the other end of your connection. This is considered a very bad thing.
-
Aug 23rd, 2022, 05:18 PM
#5
Banned
Re: Winsock state not changing
The main goal now is to make sure all connection is closed which works well but the username and room count gets stuck and left behind and now to fix this I need support.
ok, I need your help on this. this will work if you kindly assist me I checked.
I tried closing the client multiple ways by pressing the X, from task manager, taskbar right click close, vb6 ide just press stop on ide.
open one client, close it normally all ok.
open two clients or 3 close normally all ok.
open one,two,three clients but right click taskbar on all exe and exit some data in server stays on but sockets closed for all which is good thing.
server side
this code here adds
PacketArray(6) is username
PacketArray(8) room name
Code:
lstUsers.Nodes.Add , , , PacketArray(6) & "/" & PacketArray(8)
Now I added
Code:
lstUsers.Nodes.Add , , , PacketArray(6) & "/" & PacketArray(8)
List1.AddItem PacketArray(6) & "/" & PacketArray(8) & "/" & Index
using list1 I will need to clean up the mess and remove data using the index.
scan and compare list1 with lstUsers.Nodes and check which index was closed and remove the list1 data from lstUsers
Code:
Private Sub Ws_Close(Index As Integer)
Dim x As Integer
Dim ii As Integer
For ii = 1 To lstUsers.Nodes.Count
For x = 0 To List1.ListCount - 1
Dim demopacket() As String
demopacket() = Split(List1.List(x), "/")
'demopacket(0) username
'demopacket(1) roomname
'demopacket(2) index
If InStr(lstUsers.Nodes(ii).Text, demopacket(2)) Then
lstUsers.Nodes.Remove ii
List1.RemoveItem x
End If
Next
Next
end sub
or
Code:
Private Sub Ws_Close(Index As Integer)
On Error Resume Next
Dim x As Integer
Dim ii As Integer
For ii = 1 To lstUsers.Nodes.Count
For x = 0 To List1.ListCount - 1
Dim demopacket() As String
demopacket() = Split(List1.List(x), "/")
'demopacket(0) username
'demopacket(1) roomname
'demopacket(2) index
If InStr(lstUsers.Nodes(ii).Text, demopacket(0)) Then
If InStr(List1.List(x), Index) Then
lstUsers.Nodes.Remove ii
List1.RemoveItem x
End If
End If
Next
Next
End Sub
ok updated.
this works
Code:
Private Sub Ws_Close(Index As Integer)
Dim demopacket() As String
Ws(Index).Close
If foundd = False Then
Call RemoveUser(nom)
Call RemoveUserFromRoom(nom)
Call RoomCount(nom1, False)
End If
Label1.Caption = Label1.Caption - 1
On Error Resume Next
Dim X As Integer
Dim ii As Integer
For ii = 1 To lstUsers.Nodes.Count
For X = 0 To List1.ListCount - 1
demopacket() = Split(List1.List(X), "/")
'demopacket(0) username
'demopacket(1) roomname
'demopacket(2) index
If InStr(lstUsers.Nodes(ii).Text, demopacket(0)) Then
'If InStr(demopacket(2), Index) Then
lstUsers.Nodes.Remove ii
List1.RemoveItem X
Debug.Print "aaaaaaaa"
'End If
End If
Next
Next
End Sub
why is
List1.RemoveItem X
Debug.Print "aaaaaaaa"
not firing
can you kindly help clean this up this is something am looking to do.
Last edited by tuffan; Aug 23rd, 2022 at 05:43 PM.
-
Aug 29th, 2022, 02:24 PM
#6
Member
Re: Winsock state not changing
probably it will work
Code:
Private Sub Timer1_Timer()
if timer1.tag <> cstr(winsock1.state) then
timer1.tag = cstr(winsock1.state)
Select Case Winsock1.State
case 0
Debug.Print "sckClosed"
Winsock1.RemoteHost = "192.168.0.160"
Winsock1.RemotePort = "10055"
Winsock1.Connec
Case 6
Debug.Print "sckConnecting"
Case 7
Debug.Print "sckConnected"
case 9
Debug.Print "sckError"
winsock1.close
End Select
end if
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|