Solved

Winsock control hanging at sckConnecting

Posted on 2002-07-10
8
1,308 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
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

757 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

20 Experts available now in Live!

Get 1:1 Help Now