UDP question
Dar Scott
dsc at swcp.com
Fri Nov 10 14:44:42 EST 2006
On Nov 10, 2006, at 8:50 AM, Andre Garzia wrote:
> The client will write to the server then it will read from the
> socket to see if there was any answer.
That's what I tried to do, but (unless it was changed in the past two
years) that is not how it works for UDP. I would have preferred
something like that. It makes it more like TCP. In my message level
scripts I make them more alike. Scott Raney set me straight on this
some time ago when I reported bugs on the above method.
> The client is able to write to the server fine, the datagrams
> arrive nicelly. The server is not able to answer back, no error is
> reported by the write to socket message but nothing is returned to
> the server, the read from socket message after the write to socket
> on the client returns empty. I've sent more than 1k packets, they
> could not be all droped since on one way it all works fine but on
> the other way they simply don't work.
Open the client-to-server with a callback. For UDP the callback is
not a callback for when the open completes, it completes
immediately. It is the callback for any return packets. This is the
same kind of callback as 'accept' gets.
On the server end, handle the response with the handler for the
'accept' callback. The IP address & port is in the parameters.
There is a socket to that destination open. Send back any packets
you need (usually one) and then close it using the provided socket id.
For both that callback and the one for the server's accept you should
close the incoming connection.
Rev doesn't allow specifying your local port, but you can crisscross
one-way IP if you don't like the above methods.
If you have both a TCP 'accept' and a UDP 'accept' on the same port
number, they look the same in the openSockets. When you close one or
otherwise refer to one, you might not be closing or working with the
one you think.
It's been a while since I have used UDP at this level on Rev, so
there may have been changes.
Dar
More information about the use-livecode
mailing list