Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > Communications > using winsock control...after connecting to the client and disconect i cant reconnect


Reply
 
Thread Tools Display Modes
  #1  
Old 06-24-2002, 01:38 AM
andreww
Guest
 
Posts: n/a
Default using winsock control...after connecting to the client and disconect i cant reconnect


using the host program i connect to the client program

but after disconnecting from the client program
i cant reconnect to it

i have tested the host program so i know it isnt it
what could be wrong?
heres the client code:
-----------------------------------------------------------
Private Sub Form_Load()
Winsock1.Listen
End Sub

Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)
If Winsock1.State <> sckClosed Then Winsock1.Close
Winsock1.Accept requestID
End Sub

Private Sub Winsock1_DataArrival(ByVal bytesTotal As Long)
Dim strIncoming As String
Winsock1.GetData strIncoming
txtMessageBoard.Text = txtMessageBoard.Text & strIncoming & vbCrLf
End Sub

Private Sub Winsock1_Error(ByVal Number As Integer, Description As String, ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, ByVal HelpContext As Long, CancelDisplay As Boolean)
Winsock1.Close
End Sub
Reply With Quote
  #2  
Old 06-24-2002, 01:45 AM
Navi
Guest
 
Posts: n/a
Default

i think the problem is here

Private Sub Form_Load()
Winsock1.Listen
End Sub



shoul;d be :

Private Sub Form_Load()
Winsock1.LocalPort = 12345
Winsock1.Listen
End Sub


i think..
Reply With Quote
  #3  
Old 06-24-2002, 01:50 AM
andreww
Guest
 
Posts: n/a
Default

sorry, i forgot to say ive already added that to the winsock control
so it aint that

ive already connected to the client..then i disconnect, then reconnect is the problem
Reply With Quote
  #4  
Old 06-24-2002, 06:14 AM
ChiefRedBull's Avatar
ChiefRedBull ChiefRedBull is offline
ISearchGoogle

Retired Moderator
* Expert *
 
Join Date: May 2001
Location: england
Posts: 6,321
Default

You have to make sure that both sides reset their sockets back to their original states.
On the server side, watch the the _Close and _Error events.
Code:
Private Sub Server_Error(ByVal Number As Integer, Description As String, _
        ByVal Scode As Long, ByVal Source As String, ByVal HelpFile As String, _
        ByVal HelpContext As Long, CancelDisplay As Boolean) 

  ' reset the socket
  Server.Close 
  Server.Listen
End Sub

Private Sub Server_Close() 

  ' reset the socket
  Server.Close 
  Server.Listen
End Sub
This should reset the server socket so that whenever it closes, it automatically relistens.
__________________
Chuck Norris ordered a Big Mac at Burger King, and got one.
Reply With Quote
  #5  
Old 06-24-2002, 09:23 AM
andreww
Guest
 
Posts: n/a
Default

what about the client side?
Reply With Quote
  #6  
Old 06-24-2002, 09:45 AM
Agent Agent is offline
Senior Contributor
 
Join Date: Oct 2001
Location: North Carolina of the U.S.A.
Posts: 1,008
Default

I'm confused. In your original post you have the client form
listening for connection? Isn't that the server form then? I
may be wrong again, though.

It seems on your client form, you should make it re-listen
when it closes. But on your server form, it should just say
it is closed. I don't think it is right for it to automatically try to
reconnect.
__________________
Search the forums if time permits and use the [vb][/vb] tags to put VB code in your post.
Reply With Quote
  #7  
Old 06-24-2002, 10:06 AM
ChiefRedBull's Avatar
ChiefRedBull ChiefRedBull is offline
ISearchGoogle

Retired Moderator
* Expert *
 
Join Date: May 2001
Location: england
Posts: 6,321
Default

Let's just be clear about terminology.

Server is the one that listens, that serves up stuff to the client.
Client is the one that connects to the server, in order to retrieve stuff.
__________________
Chuck Norris ordered a Big Mac at Burger King, and got one.
Reply With Quote
  #8  
Old 06-24-2002, 05:37 PM
andreww
Guest
 
Posts: n/a
Default

Sorry I got the server and client mixed up.

I mean ...I dont think the ports reopening after i close it

I tried added winsock1.listen
but it wwont let me run it twice
Reply With Quote
  #9  
Old 06-24-2002, 05:52 PM
Agent Agent is offline
Senior Contributor
 
Join Date: Oct 2001
Location: North Carolina of the U.S.A.
Posts: 1,008
Default

You don't think it is, or you don't want it to?

If you can't listen twice, check first to see if it is listening...
Code:
If winsock1.state <> sckListening then
  winsock1.close
  winsock1.listen
end if
__________________
Search the forums if time permits and use the [vb][/vb] tags to put VB code in your post.
Reply With Quote
  #10  
Old 06-25-2002, 05:41 AM
andreww
Guest
 
Posts: n/a
Default

thanx agent
i was just curious tho
before when it wasnt working
the winsock state would be 8
not 7 "listening"

i looked 8 up and its nothing
anyone know what this is?
Reply With Quote
  #11  
Old 06-25-2002, 05:47 AM
Squirm's Avatar
Squirm Squirm is offline
Political Coder

Retired Moderator
* Guru *
 
Join Date: Mar 2001
Location: London, England
Posts: 8,037
Default

If you search the F2 Object Browser for StateConstants you'll find that 8 is sckClosing - Socket is closing connection to a remote computer
__________________
Search the forums | Use [vb][/vb] tags | Still IRCing
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->