Computing.Net > Forums > Programming > VB: Socket Connection Request

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

VB: Socket Connection Request

Reply to Message Icon

Name: JoeBrewski
Date: March 14, 2004 at 13:13:40 Pacific
OS: XP Home
CPU/Ram: Athlon 2500+/1.5GB
Comment:

Question on sockets (newbie at it) in VB6. Using WinSock controls on a form. When I run the following code, the socket trying to connect never goes into a state of sckConnected (sits in sckConnecting status). I've checked the source/destination IP addresses and ports, and they are fine (listening on one port, trying to connect into that port from another). Testing on LocalHost (using the .LocalIPAddress to use the physical IP and not hitting the DNS).

The Code:

(Socket attempting connection - runs a function)

Public Function SockConnect(sckSend As Winsock, strAddr As String, intPort As Integer) As Boolean

Dim intWait As Integer

sckSend.Close
sckSend.LocalPort = 451
sckSend.Protocol = sckTCPProtocol

' Call sckSend.Bind(intPort, strAddr)

sckSend.RemoteHost = sckSend.LocalIP
sckSend.RemotePort = intPort

sckSend.Connect
Call Sleep(1000)

While sckSend.State <> sckConnecting And intWait < 5
DoEvents
Call Sleep(1000)
intWait = intWait + 1
Wend
Call WriteLog(gstrLogFile, "State is " & sckSend.State)
If intWait >= 5 Then
SockConnect = False
Else
If sckSend.State = sckConnected Then
SockConnect = True
Else
SockConnect = False
End If
End If

End Function

(Socket Receiving Connection Request)

Private Sub sckListen_ConnectionRequest(Index As Integer, ByVal requestID As Long)

If sckListen(Index).State <> sckClosed Then
intSockets = intSockets + 1
Load sckListen(intSockets)
sckListen(intSockets).Close
sckListen(intSockets).LocalPort = 450
sckListen(intSockets).Accept requestID
lblStatus = "Connection " & requestID & " accepted from " & sckListen lblStatus.Refresh
frmMain.Refresh
(intSockets).RemoteHostIP & ":" & sckListen(1).RemotePort & "."
Call WriteLog(gstrLogFile, lblStatus.Caption)
' MsgBox ("Accepted")
Else
MsgBox ("Socket Closed - Cannot Accept Connection.")
End If

End Sub

---

Help Greatly Appreciated

Joe



Sponsored Link
Ads by Google

Response Number 1
Name: JoeBrewski
Date: March 15, 2004 at 09:56:01 Pacific
Reply:

Figured it out with some more reading on the web.

(1) Upped the port on the accept
(2) Put in DoEvents all over the place
(3) Rebooted the PC to alleviate a 'ports-in-limbo' issue that seemed to keep coming up.

Learning the socket stuff so hopefully I can apply it at work with some client/server apps that can someday directly communicate with eachother.

Joe


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: VB: Socket Connection Request

Interrupting Socket::Connect C++ www.computing.net/answers/programming/interrupting-socketconnect-c/14267.html

VB .Net - Connection object www.computing.net/answers/programming/vb-net-connection-object/13065.html

VB & Telnet function www.computing.net/answers/programming/vb-amp-telnet-function/3379.html