Solved

Winsock control hanging at sckConnecting

Posted on 2002-07-10
8
1,310 Views
Last Modified: 2013-11-13
I'm using the winsock control to create a SOCKS4a proxy server. Recently, I've encountered a problem that I've never had before: when I try to connect to the remote server, it no longer works.

This is the snippet of code that is being called when the data the client has sent is put into a user defined type [skData]. It's sticking at the loop because sckConnOut(Index).State is sticking at 6 (sckConnecting). Do you know why this might be?

Data:
skData.strHostName="messenger.hotmail.com"
skData.lonDestPort=1863
skData.strDestIp="0.0.0.110"
lonTimeout=20000
sckConnOut(index) is the connection to the remote host
sckConnIn(index) is the connection to the client sending the SOCKS requests.,

skReply.bytVersion = 0
skReply.bytCommand = 90
skReply.lonDestPort = skData.lonDestPort
skReply.strDestIp = CStr(skData.strDestIp)
If skData.strHostName = "" Then skData.strHostName = CStr(Replace(skData.strDestIp, Chr(0), ""))

'sckConnOut(Index).Close
sckConnOut(Index).RemoteHost = skData.strHostName
sckConnOut(Index).RemotePort = skData.lonDestPort
sckConnOut(Index).Connect 'skData.strHostName, skData.lonDestPort
lonStartTime = GetTickCount
Do
    DoEvents
Loop Until sckConnOut(Index).State = sckConnected Or (GetTickCount - lonStartTime) >= lonTimeOut

If (GetTickCount - lonStartTime) >= lonTimeOut Then
    sckConnOut(Index).Close
    sckConnIn(Index).Close
    Exit Sub
End If

sckConnIn(Index).Tag = "1"



I've set up a project to test the code and it works fine...

Dim lonTimeout As Long
Private Declare Function GetTickCount Lib "kernel32.dll" () As Long
Private Sub Form_Load()
    Dim lonStartTime As Long
    Winsock1.RemoteHost = "messenger.hotmail.com"
    Winsock1.RemotePort = 1863
    lonTimeout = 20000
    Winsock1.Connect
   
    lonStartTime = GetTickCount
    Do
        DoEvents
    Loop Until Winsock1.State = sckConnected Or (GetTickCount - lonStartTime) >= lonTimeout
   
    If (GetTickCount - lonStartTime) >= lonTimeout Then
        MsgBox "Connection failed"
    Else
        MsgBox "Connected"
    End If
End Sub

I'd be most appreciative if anybody could tell me if I'm making a mistake or if it's a bug in the winsock control(?)

(I'm using the VB6 SP5 version of the winsock control)
0
Comment
Question by:j3877
8 Comments
 
LVL 1

Expert Comment

by:PX
ID: 7145596
try this

While (sckConnOut(Index).State <> sckConnected Or (GetTickCount - lonStartTime) <= lonTimeOut)
   DoEvents
Wend
0
 
LVL 1

Author Comment

by:j3877
ID: 7145600
It doesn't work. It seems not to be the actual loop code (I'd already done a few tests like this to make sure [including one without a loop, but with a timer control])

Does the winsock control not like it if you issue a .connect inside another winsock control's event? that's the only reason I can think the code wouldn't work, and I can't see why that would be *makes no sense*.
0
 
LVL 1

Expert Comment

by:PX
ID: 7145622
Try this,


Close the connectiion before u make the connection:


Change ---------------
'sckConnOut(Index).Close
sckConnOut(Index).RemoteHost = skData.strHostName
sckConnOut(Index).RemotePort = skData.lonDestPort
To---------------------
sckConnOut(Index).Close
sckConnOut(Index).RemoteHost = skData.strHostName
sckConnOut(Index).RemotePort = skData.lonDestPort


Or make sure u check the status of the socket brfore u make another connection.

0
 
LVL 1

Author Comment

by:j3877
ID: 7145626
It makes no difference
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 1

Author Comment

by:j3877
ID: 7145667
It makes no difference
0
 
LVL 1

Author Comment

by:j3877
ID: 7145669
Grr. There should be an unique Id embedded in comment forms so you can't accidentally double-post.
0
 
LVL 49

Expert Comment

by:DanRollins
ID: 8002282
Hi j3877,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Refund points and save as a 0-pt PAQ.

j3877, Please DO NOT accept this comment as an answer.
EXPERTS: Post a comment if you are certain that an expert deserves credit.  Explain why.
==========
DanRollins -- EE database cleanup volunteer
0
 
LVL 1

Accepted Solution

by:
Computer101 earned 0 total points
ID: 8094156
Question placed in PAQ

Computer101
E-E Admin
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There is an easy way, in .NET, to centralize the treatment of all unexpected errors. First of all, instead of launching the application directly in a Form, you need first to write a Sub called Main, in a module. Then, set the Startup Object to th…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now