Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Winsock control hanging at sckConnecting

Posted on 2002-07-10
8
Medium Priority
?
1,328 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This video teaches viewers about errors in exception handling.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

618 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