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
Solved

Winsock control hanging at sckConnecting

Posted on 2002-07-10
8
1,317 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
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.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

829 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