Solved

Winsock control hanging at sckConnecting

Posted on 2002-07-10
8
1,319 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 1

Author Comment

by:j3877
ID: 7145626
It makes no difference
0
 
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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
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…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

733 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