Class CTCPSocket::
Connect()
Base ClassesData ItemsConstructorsDestructorsFunctionsCustom CodeGo to hierarchy chart    Prev page: CloseNext page: Connect    Show member index
Public Function Declared in:
TCPSocket.h

'Declaration' icon -- Shortcut to top of page. Declaration

virtual BOOL Connect(
    unsigned short usSourcePort,
    IP aDestinationAddress,
    unsigned short usDestinationPort);

'Description' icon -- Shortcut to top of page. Description

Connect to a remote system Choose the source address explicitly usSourcePort - OS will allocate source port

'Function Body' icon -- Shortcut to top of page. Function Body

try
{
    //Quit if not ok
    if (!CheckSocketValid())
        return FALSE;

    ///Special handling for raw sockets
    if (IsRaw())
        return SendRaw(usSourcePort,
                       aDestinationAddress,
                       usDestinationPort,
                       NULL,
                       0,
                       TCPFlag_SYN);
    else
    {
        //Set async notification
        int iResult;

        //Create the address
        sockaddr_in aSrc;

        //Set to 0
        memset(&aSrc,
               0,
               sizeof(aSrc));
        aSrc.sin_family=AF_INET;
        aSrc.sin_addr.s_addr=aDestinationAddress;
        aSrc.sin_port=htons(usDestinationPort);

        //Connect
        iResult=connect(GetHandle(),
                        (sockaddr*)&aSrc,
                        sizeof(aSrc));

        //Did we have a blocked error
        BOOL bBlocked;
        bBlocked=FALSE;

        //Check the result
        if (iResult==GetErrorCode())
        {
            //Check is it blocking error so we can ignore
            if (WSAGetLastError()!=WSAEWOULDBLOCK)
                SetLastError("Connect");
            else
            {
                //Indicate it's blocked error
                bBlocked=TRUE;
                iResult=!GetErrorCode();
            }
        }
        else
            //Report the error
            SetLastError("Connect");

        if (iResult!=GetErrorCode())
        {
            //Check if we are a sync socket
            if (!IsAsyncClass())
                SetConnectionStatus(TRUE);

            //Save where we are connected
            SetConnectedTo(aSrc);
        }

        //Done
        if (!bBlocked)
            return iResult!=GetErrorCode();
        else
            return FALSE;
    }
}
ERROR_HANDLER_RETURN("Connect",FALSE)

'See Also' icon -- Shortcut to top of page. See Also

Class Overview Class Overview  |  Public base class CSpoofSocket  |  Hierarchy Chart Hierarchy Chart


Get Surveyor!This web site was generated using Surveyor V4.50.811.1.  Click here for more information. Site content copyright © 2003 Komodia LTD.. See the About page for additional notices. This page last updated: 24 Feb 2003.