Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > Communications > winsock connecting state, loop

Thread Tools Display Modes
Old 06-20-2003, 07:24 PM
HelpMoiPlz HelpMoiPlz is offline
Join Date: Jun 2003
Posts: 29
Default winsock connecting state, loop

Private Sub mnuFileConnect_Click()
On Error Resume Next
Dim iServ As String

iServ = "ipnumber"

If iServ = "" Then Exit Sub

'Disable menus
frmMain.mnuFileConnect.Enabled = False
frmMain.mnuFileExit.Enabled = False

'Connect to the server
With wsk
.Protocol = sckTCPProtocol
.RemotePort = ServerPort
.RemoteHost = iServ
End With

Call ShowText("Connecting to server" & vbCrLf & vbCrLf)
StatusBar2.Panels(1).Text = "Status: Connecting"
End Sub

THIS IS PART OF THE SUB i took from my game, the connecting part.. can sombody please modify it, to check the connection state and make it write it to the statusbar,, and also if winsock state is 0, not connected.. then it will keep on trying to connect.. the problem with my code is.. if the server aint up.. u have to keep reconnecting, because it dont like loop... please help
Reply With Quote
Old 06-20-2003, 08:05 PM
HelpMoiPlz HelpMoiPlz is offline
Join Date: Jun 2003
Posts: 29
Default help

If Winsock1.State = 0 Then StatusBar2.Panels(1).Text = "Closed"
If Winsock1.State = 1 Then StatusBar2.Panels(1).Text = "Open"
If Winsock1.State = 2 Then StatusBar2.Panels(1).Text = "Listening"
If Winsock1.State = 3 Then StatusBar2.Panels(1).Text = "Pending"
If Winsock1.State = 4 Then StatusBar2.Panels(1).Text = "Resolving"
If Winsock1.State = 5 Then StatusBar2.Panels(1).Text = "Resolved"
If Winsock1.State = 6 Then StatusBar2.Panels(1).Text = "Connecting"
If Winsock1.State = 7 Then StatusBar2.Panels(1).Text = "Connected"
If Winsock1.State = 8 Then StatusBar2.Panels(1).Text = "Closing"
If Winsock1.State = 9 Then StatusBar2.Panels(1).Text = "Error"

perhaps this will help people write me out a better sub
Reply With Quote
Old 06-21-2003, 03:21 AM
Squidge Squidge is offline
Join Date: Mar 2003
Location: Manchester! England!
Posts: 872

hey, erm well its against posting guidline to write the code for you, try asking a pesific question
Reply With Quote
Old 06-21-2003, 07:33 PM
Banjo's Avatar
Banjo Banjo is offline
Hell's Angel

Retired Moderator
* Guru *
Join Date: Jul 2001
Location: Yorkshire, UK
Posts: 10,394

Is that a specific question or a pacific question?

Sorry, couldn't resist.
A wise one man once said "what you talking about dog breath"
Reply With Quote
Old 06-23-2003, 04:15 PM
blindwig's Avatar
blindwig blindwig is offline
Ultimate Contributor

* Expert *
Join Date: Jun 2003
Location: New York, NY
Posts: 1,929

if it doesn't loop automatically, you need to write you own loop. Don't forget to include a time-out, or you could loop indefinately. Like this:

LastTime=Now Do Call AttemptConnection Loop Until (wsk.state=sckConnected) or (TimeSince(LastTime)>Timeout)
Of course, you need to define the AttemptConnection sub and the TimeSince function, and declare the Timeout value, but you get the idea...
And if your timeout value is too high, you might need a DoEvents call to continue running other controls.
Reply With Quote
Old 06-24-2003, 03:25 PM
HelpMoiPlz HelpMoiPlz is offline
Join Date: Jun 2003
Posts: 29

thanks to all your help guys, its sorted now
Reply With Quote

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

Similar Threads
Thread Thread Starter Forum Replies Last Post
Standards and Practices loquin Tutors' Corner 10 07-28-2006 12:16 PM
vc++6: any1 know how to use threads eg _beginthread(), _endthread() funcs clockworkorange Miscellaneous Languages 2 06-09-2003 09:20 PM
Winsock slow or infinite loop on connect Dark_Nova Communications 4 10-11-2002 10:03 AM
Timers jemerico General 7 05-30-2001 05:30 PM


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.
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
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..