Sign in to follow this  
Followers 0
Glyph

Problem with MSWinsock.Winsock

3 posts in this topic

#1 ·  Posted (edited)

Global Const $SCKTCPPROTOCOL = 0
Global Const $SCKUDPPROTOCOL = 0x01
Global Const $SCKCLOSED = 0
Global Const $SCKOPEN = 0x01
Global Const $SCKLISTENING = 0x02
Global Const $SCKCONNECTIONPENDING = 0x03
Global Const $SCKRESOLVINGHOST = 0x04
Global Const $SCKHOSTRESOLVED = 0x05
Global Const $SCKCONNECTING = 0x06
Global Const $SCKCONNECTED = 0x07
Global Const $SCKCLOSING = 0x08
Global Const $SCKERROR = 0x09

Func ConnectTCP($sAddr, $iPort, $iTimeout)
    Local $oSocket, $timer
    $oSocket = ObjCreate("MSWinsock.Winsock")
    $oSocket.Protocol = $SCKTCPPROTOCOL ; set protocol to be tcp
    $timer = TimerInit()
    $oSocket.Connect($sAddr, $iPort)
    While 1
        If $oSocket.State = $SCKERROR Then
            $oSocket = 0
            Return -2 ;connection error (will give up for now)
        EndIf
        If $oSocket.State = $SCKCONNECTED Then
            $oSocket.Close
            $oSocket = 0
            Return 0
            ;Return $oSocket ; return object for connection
        EndIf
        If TimerDiff($timer) > $iTimeout Then
   $oSocket.Close
            $oSocket = 0
            Return -3 ; connection timeout
        EndIf
    WEnd
EndFunc   ;==>Connect

After running that I get this:

==> Variable must be of type "Object".:

$oSocket.Protocol = $SCKTCPPROTOCOL

$oSocket^ ERROR

I see MSWINSCK.OCX in my system32. (It has been unregistered and registered, still did nothing)

Do I have to install some special MSWinsock thing? Am I missing something?

I hope you can reply.

Edited by Glyph

tolle indicium

Share this post


Link to post
Share on other sites



Why not just use the built in network functions?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0