|
-
Jul 3rd, 2003, 03:35 PM
#1
Thread Starter
Lively Member
Winsock won't close {RESOLVED}
I have a listbox containing user's computer names. When I click on a name, my single winsock control connects to that user's computer fine. But when I click on a different name, I have the code
to close Winsock1 and enable it to connect to that user. But the event
Private Sub Winsock1_Close()
End Sub
never fires and therefore Winsock1 never closes. How can I make it close??
Last edited by vb_paladin; Jul 6th, 2003 at 10:01 AM.
-
Jul 3rd, 2003, 03:49 PM
#2
Lively Member
I don't think that DoEvents should really be there after your Winsock1.Close.
have a public variable holding the state of the winsock and check it before connection to another computer
VB Code:
Dim wconn As Boolean
Private Sub Winsock1_Close()
wconn = False
End Sub
then in your listbox code
VB Code:
Winsock1.Close
If wconn = False Then
wconn = True
'connect
End If
Anticipation of death is worse than death itself
-
Jul 3rd, 2003, 04:50 PM
#3
Thread Starter
Lively Member
It still doesnt work. This is the code for my listbox.
When the user clicks a different name in the listbox, sckOut should disconnect from the current user it is connected to, and reconnect to the new username that is selected.
VB Code:
Private Sub lstUsers_Click()
If lstUsers.List(lstUsers.ListIndex) = strLocalName Then
Exit Sub
ElseIf lstUsers.List(lstUsers.ListIndex) = strUserName Then
Exit Sub
End If
lstUsers.Enabled = False
If sckOut.State = sckConnected Then
sckOut.SendData "DISCONNECTING_USER": DoEvents
sckOut.Close
End If
strUserName = lstUsers.List(lstUsers.ListIndex)
strUserPort = lstPorts.List(lstUsers.ListIndex)
sckOut.RemoteHost = strUserName
sckOut.RemotePort = strUserPort + 1
sckOut.Connect
End Sub
-
Jul 3rd, 2003, 09:29 PM
#4
Frenzied Member
The Private Sub:
VB Code:
Private Sub Winsock1_Close()
End Sub
Only fires when the connection is closed by the remote host. You can make winsock connect right after you close it in your code..
-
Jul 4th, 2003, 07:38 PM
#5
Thread Starter
Lively Member
so I don't have to send a message telling the remote host to close the winsock
VB Code:
sckOut.SendData "DISCONNECTING_USER
All I have to do is do sckOut.Close locally and then the remote host's Winsock1_Close() event will fire and disconnect, correct?
-
Jul 5th, 2003, 01:50 AM
#6
Frenzied Member
Should do.
-
Jul 5th, 2003, 10:56 AM
#7
Frenzied Member
Re: Winsock won't close
Originally posted by vb_paladin
and therefore Winsock1 never closes. How can I make it close??
Spajeoly answered part of your question, but from the above quote, it appears that there may more to your problem.
Do you know for a fact that Winsock1 does not close? Or was this an assumption because you didn't see the Winsock1_Close sub fire?
If you are hardcoding a LocalPort number, the connection will remain in a TIME_WAIT mode for about 4 minutes after closing and you will not be able to connect during that time. Be sure to set LocalPort to zero and let the system select an unused port number every time you connect.
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
|