Thread View: borland.public.cppbuilder.internet.socket
2 messages
2 total messages
Started by Orlando Lopez
Sun, 19 Mar 2006 22:18
Bind to a specific port
Author: Orlando Lopez
Date: Sun, 19 Mar 2006 22:18
Date: Sun, 19 Mar 2006 22:18
30 lines
1864 bytes
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.
Re: Bind to a specific port
Author: Remy Lebeau (TeamB)
Date: Mon, 20 Mar 2006 00:23
Date: Mon, 20 Mar 2006 00:23
31 lines
1935 bytes
1935 bytes
"Orlando Lopez" <hlopezrd@hotmail.com> wrote in message
news:441de6db@newsgroups.borland.com...
> 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.
As they should be, because the socket is not connected yet when the event is
triggered, and those proerties only work on connected sockets.
> What can I do?
Like every oter event handler in the VCL, the Sender parameter points to the
particular object that is triggering the event - in this case, the
TClientSocket object that you are looking for:
void __fastcall TForm1::ClientSocket1Lookup(TObject *Sender,
TCustomWinSocket *Socket)
{
TClientSocket *Client = dynamic_cast<TClientSocket*>(Sender);
if( !Client )
return;
// ...
}
Gambit
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads