 |
BorlandTalk.com Borland discussion newsgroups
|
| View previous topic :: View next topic |
| Author |
Message |
Kresten Tolstrup Guest
|
Posted: Tue Mar 27, 2007 6:46 pm Post subject: UDP socket |
|
|
Hello
Does anyone have a simple example, that shows how to use TUdpSocket. I use C++ builder 6.0. When I try to send anything I receive errorcode 10038. I setup the local and remote port numbers, then I call connect(), I have also tried with open(), after that I setup remote host and call SendBuf, then the Event UdpSocketError is called. There is not any server or client settings, is that correct?.
Best Regards
Kresten |
|
| Back to top |
|
 |
Kresten Tolstrup Guest
|
Posted: Thu Mar 29, 2007 5:06 pm Post subject: Re: UDP socket |
|
|
"Kresten Tolstrup" <kt (AT) danphone (DOT) com> wrote:
| Quote: |
Hello
Does anyone have a simple example, that shows how to use TUdpSocket. I use C++ builder 6.0. When I try to send anything I receive errorcode 10038. I setup the local and remote port numbers, then I call connect(), I have also tried with open(), after that I setup remote host and call SendBuf, then the Event UdpSocketError is called. There is not any server or client settings, is that correct?.
Best Regards
Kresten
|
When I setup the following:
if (bServer)
{
UdpSocket->RemoteHost = "<Any>";
UdpSocket->RemotePort = 0;
UdpSocket->LocalHost = "<Any>";
UdpSocket->LocalPort = 34100;
}
else
{
UdpSocket->RemoteHost = "192.168.0.27";
UdpSocket->RemotePort = 34100;
UdpSocket->LocalHost = "<Any>";
UdpSocket->LocalPort = 0;
}
UdpSocket->Open();
there are no errors when bServer is false, and the Event UdpSocketConnect is called.
When bServer is true the event UdpSocketError is called with socket error 10049. If I then change RemoteHost to 127.0.0.1, then UdpSocketError is not called, but if it shall work as a server, the remote host cannot be specified. So how shall it be setup to a server ?
The C Builder Developer's guide say, on page 37-7, that the LocalPort property shall be set, and nothing else. It also says that there is an OnAccept event, that is called when a client has connected, but UdpSocket don't have this event.
For client sockets it says that the remote port and remote address shall be set and nothing else.
Best Regards
Kresten |
|
| Back to top |
|
 |
Paul at NCF Guest
|
Posted: Fri Mar 30, 2007 2:48 am Post subject: Re: UDP socket |
|
|
Hi,
I've not used this component, but I have used the Indy UDP components. Indy
has separate Client and Server components, whereas this borland component
seems to be doing both functions, which seems strange and with no obvious
settings for setting it up for either.
I had a quick play with it but not found out much so far.
Paul
"Kresten Tolstrup" <kt (AT) danphone (DOT) com> wrote in message
news:4609120b$1 (AT) newsgroups (DOT) borland.com...
| Quote: |
Hello
Does anyone have a simple example, that shows how to use TUdpSocket. I use
C++ builder 6.0. When I try to send anything I receive errorcode 10038. I
setup the local and remote port numbers, then I call connect(), I have
also tried with open(), after that I setup remote host and call SendBuf,
then the Event UdpSocketError is called. There is not any server or client
settings, is that correct?.
Best Regards
Kresten |
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Fri Mar 30, 2007 4:15 am Post subject: Re: UDP socket |
|
|
"Kresten Tolstrup" <kt (AT) danphone (DOT) com> wrote in message
news:4609120b$1 (AT) newsgroups (DOT) borland.com...
| Quote: | Does anyone have a simple example, that shows how
to use TUdpSocket. I use C++ builder 6.0.
|
Borland's socket components for CLX are horribly written. I strongly
advise you to not use them at all. There are plenty of third-party
components that are much better.
| Quote: | When I try to send anything I receive errorcode 10038.
|
WSAENOTSOCK (10038)
Socket operation on non-socket.
An operation was attempted on something that is not a socket.
Either the socket handle parameter did not reference a valid socket,
or for select, a member of an fd_set was not valid.
| Quote: | I setup the local and remote port numbers, then I call connect(),
I have also tried with open(), after that I setup remote host and
call SendBuf, then the Event UdpSocketError is called.
|
You have to specify the Host before you call Open() or Connect(). You
can't set it afterwards.
Gambit |
|
| Back to top |
|
 |
Kresten Tolstrup Guest
|
Posted: Tue Apr 10, 2007 3:23 pm Post subject: Re: UDP socket |
|
|
Hi,
I have now used the Indy components, and it is working, but isn't there any callback function in the client class, like the IdUDPServerUDPRead function in the server class, or do I have to poll the client class to see if it has received anything?
Best Regards
Kresten
"Paul at NCF" <notplmacca (AT) clara (DOT) co.uk> wrote:
| Quote: | Hi,
I've not used this component, but I have used the Indy UDP components. Indy
has separate Client and Server components, whereas this borland component
seems to be doing both functions, which seems strange and with no obvious
Paul
"Kresten Tolstrup" <kt (AT) danphone (DOT) com> wrote in message
news:4609120b$1 (AT) newsgroups (DOT) borland.com...
Hello
Does anyone have a simple example, that shows how to use TUdpSocket. I use |
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Tue Apr 10, 2007 10:02 pm Post subject: Re: UDP socket |
|
|
"Kresten Tolstrup" <kt (AT) danphone (DOT) com> wrote in message
news:461b577e$1 (AT) newsgroups (DOT) borland.com...
| Quote: | I have now used the Indy components, and it is working, but
isn't there any callback function in the client class, like the
IdUDPServerUDPRead function in the server class
|
No, there is not. But you can use TIdUDPServer for both a client and
a server, as it has all of the same writing methods that TIdUDPClient
has. The only difference between TIdUDPClient and TIdUDPServer is
that the former exposes Host and Port properties, which you don't
really need, and the latter allows listening on multiple local IP/Port
pairs, which you only need 1 of on the client side. Otherwise, they
are both the same, as they both derive from TIdUDPBase, which
implements most of the work equally between them.
| Quote: | do I have to poll the client class to see if it has received
anything? |
Yes, you would.
Gambit |
|
| Back to top |
|
 |
Kresten Tolstrup Guest
|
Posted: Thu Apr 12, 2007 4:04 pm Post subject: Re: UDP socket |
|
|
Hi
OK, I use the server as client to, the event OnUDPRead is then called when a UDP packet is received, and I can get the data from the Tstream, but how can I get the size, if I use the function AData->GetSize(), then I get the error "not accessible".
Kresten
"Remy Lebeau \(TeamB\)" <no.spam (AT) no (DOT) spam.com> wrote:
| Quote: |
"Kresten Tolstrup" <kt (AT) danphone (DOT) com> wrote in message
news:461b577e$1 (AT) newsgroups (DOT) borland.com...
I have now used the Indy components, and it is working, but
isn't there any callback function in the client class, like the
IdUDPServerUDPRead function in the server class
No, there is not. But you can use TIdUDPServer for both a client and
a server, as it has all of the same writing methods that TIdUDPClient
has. The only difference between TIdUDPClient and TIdUDPServer is
that the former exposes Host and Port properties, which you don't
really need, and the latter allows listening on multiple local IP/Port
pairs, which you only need 1 of on the client side. Otherwise, they
are both the same, as they both derive from TIdUDPBase, which
implements most of the work equally between them.
do I have to poll the client class to see if it has received
anything?
Yes, you would.
Gambit
|
|
|
| Back to top |
|
 |
Remy Lebeau (TeamB) Guest
|
Posted: Thu Apr 12, 2007 10:13 pm Post subject: Re: UDP socket |
|
|
"Kresten Tolstrup" <kt (AT) danphone (DOT) com> wrote in message
news:461e0413$1 (AT) newsgroups (DOT) borland.com...
| Quote: | how can I get the size, if I use the function AData->GetSize(),
then I get the error "not accessible".
|
Use the public Size property instead. GetSize() is the getter method
for the property.
Gambit |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|