Thread View: borland.public.cppbuilder.internet.socket
5 messages
5 total messages
Started by Cagatay Undeger
Thu, 05 Aug 2004 20:58
Restricting Local IP in TServerSocket
Author: Cagatay Undeger
Date: Thu, 05 Aug 2004 20:58
Date: Thu, 05 Aug 2004 20:58
15 lines
1307 bytes
1307 bytes
Hello, I would like to select only one of the local addresses for listening on a port when more than one ethernet card and ip exist on a single machine. Is it possible to do that using TServerSocket? For example: when there is 2 athernet cards that have 2 IPs: 10.0.0.5 and 10.0.0.6. if a TServerSocket is activated on a single port, clients can connect from both 10.0.0.5 and 10.0.0.6, but I would like to select just one of the IPs. Thanks in advance, Cagatay
Re: Restricting Local IP in TServerSocket
Author: Remy Lebeau (TeamB)
Date: Thu, 05 Aug 2004 21:31
Date: Thu, 05 Aug 2004 21:31
16 lines
1555 bytes
1555 bytes
"Cagatay Undeger" <cagatay@interaktif.gen.tr> wrote in message news:41129f35$1@newsgroups.borland.com... > I would like to select only one of the local addresses for > listening on a port when more than one ethernet card and > ip exist on a single machine. Is it possible to do that using > TServerSocket? Yes. Derive a new class from TServerSocket, then you will have access to its protected Address property. That value is used to bind the server to a particular IP. Since it is not publically accessible, its value is usually empty, thus the server normally binds to all available addresses. Gambit
Re: Restricting Local IP in TServerSocket
Author: Cagatay Undeger
Date: Thu, 05 Aug 2004 22:20
Date: Thu, 05 Aug 2004 22:20
52 lines
2402 bytes
2402 bytes
Hi,
I tried what you proposed but did not work.
I created a class as follows:
class TMyServerSocket : public TServerSocket
{
public:
__fastcall virtual TMyServerSocket (Classes::TComponent* AOwner)
: TServerSocket (AOwner)
{
}
void SetLocalAddress ( AnsiString address )
{
Address = address;
};
};
Then I connected as follows:
TServerSocket * ServerSocket = new TMyServerSocket(NULL);
((TMyServerSocket*)ServerSocket)->SetLocalAddress ( ip );
ServerSocket->Port = port;
ServerSocket->Active = true;
But when I print the Socket->LocalAddress property,
it writes 0.0.0.0 and still works with multiple IP.
Cagatay
"Remy Lebeau (TeamB)" <gambit47.no.spam@no.spam.yahoo.com> wrote in message
news:4112a709$1@newsgroups.borland.com...
>
> "Cagatay Undeger" <cagatay@interaktif.gen.tr> wrote in message
> news:41129f35$1@newsgroups.borland.com...
>
> > I would like to select only one of the local addresses for
> > listening on a port when more than one ethernet card and
> > ip exist on a single machine. Is it possible to do that using
> > TServerSocket?
>
> Yes. Derive a new class from TServerSocket, then you will have access to
> its protected Address property. That value is used to bind the server to
a
> particular IP. Since it is not publically accessible, its value is
usually
> empty, thus the server normally binds to all available addresses.
>
>
> Gambit
>
>
Re: Restricting Local IP in TServerSocket
Author: Remy Lebeau (TeamB)
Date: Thu, 05 Aug 2004 23:26
Date: Thu, 05 Aug 2004 23:26
28 lines
1770 bytes
1770 bytes
"Cagatay Undeger" <cagatay@interaktif.gen.tr> wrote in message
news:4112b291@newsgroups.borland.com...
> I tried what you proposed but did not work.
I've used it myself so I know that it does work.
Further investigation shows that it only works when the server is used in
blocking mode, though. Are you using non-blocking instead?
> I created a class as follows:
You don't need that much code. Just promote the existing property:
class TMyServerSocket : public TServerSocket
{
public:
__fastcall TMyServerSocket(TComponent *Owner) : TServerSocket(Owner)
{}
__property Address;
};
TMyServerSocket * ServerSocket = new TMyServerSocket(NULL);
ServerSocket->Address = ip;
Gambit
Re: Restricting Local IP in TServerSocket
Author: Cagatay Undeger
Date: Fri, 06 Aug 2004 13:51
Date: Fri, 06 Aug 2004 13:51
37 lines
1953 bytes
1953 bytes
Yes, I used non-blocking one ?
Cagatay
"Remy Lebeau (TeamB)" <gambit47.no.spam@no.spam.yahoo.com> wrote in message
news:4112c203$1@newsgroups.borland.com...
>
> "Cagatay Undeger" <cagatay@interaktif.gen.tr> wrote in message
> news:4112b291@newsgroups.borland.com...
>
> > I tried what you proposed but did not work.
>
> I've used it myself so I know that it does work.
>
> Further investigation shows that it only works when the server is used in
> blocking mode, though. Are you using non-blocking instead?
>
> > I created a class as follows:
>
> You don't need that much code. Just promote the existing property:
>
> class TMyServerSocket : public TServerSocket
> {
> public:
> __fastcall TMyServerSocket(TComponent *Owner) :
TServerSocket(Owner)
> {}
> __property Address;
> };
>
> TMyServerSocket * ServerSocket = new TMyServerSocket(NULL);
> ServerSocket->Address = ip;
>
>
> 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