🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.internet.socket
Article #2538

Bind to a specific port

#2538
From: Orlando Lopez
Date: Sun, 19 Mar 2006 22:18
30 lines
1864 bytes
Thanks to Gambit,
with this code I can bind a clientsocket to a specific port number:
With that said, use this code:

    #include <RtlConsts.hpp>

    void __fastcall TForm1::ClientSocket1Lookup(TObject *Sender,
TCustomWinSocket *Socket)
    {
        sockaddr_in Addr = {0};
        Addr.sin_family = PF_INET;
        Addr.sin_addr.s_addr = INADDR_ANY;
        Addr.sin_port = htons(3033);

        if( ::bind((SOCKET)Socket->SocketHandle, (sockaddr*)&Addr,
sizeof(Addr)) == SOCKET_ERROR )
        {
            int Err = WSAGetLastError();
            throw ESocketError(Rtlconsts_sWindowsSocketError,
ARRAYOFCONST((SysErrorMessage(Err), Err, 'bind')));
        }
    }

My problem is that I have an Array of TClientSocket, and when
the OnLookup event is triggered I have to check the Address and
the Port number of the current TClientSocket that is in this event to bind with an specific port.
But the RemoteAddress, LocalAddress, LocalPort, RemotePort are all nulls or cero.
What can I do?
Thanks in advance.
Technical Details
Message-ID: <441de6db@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,36510058f2db75e3,start
X-Google-Attributes: gid11508e,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Orlando Lopez" <hlopezrd@hotmail.com>
Sender: "Orlando Lopez" <hlopezrd@hotmail.com>
Reply-To: "Orlando Lopez" <hlopezrd@hotmail.com>
Subject: Bind to a specific port
Newsgroups: borland.public.cppbuilder.internet.socket
X-User-Info: 200.88.202.134     
NNTP-Posting-Host: 207.105.83.66
Message-ID: <441de6db@newsgroups.borland.com>
Date: 19 Mar 2006 15:18:51 -0700
X-Trace: newsgroups.borland.com 1142810331 207.105.83.66 (19 Mar 2006 15:18:51 -0700)
Lines: 30
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news4.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail