I'm having problems creating a UDP socket that listens for messages on
a port and (sometimes) sends messages back to the original sender of
the message.
I can receive a message over the UDP socket fine, I'm just not sure
about how to know where to send the message back, and how to properly
send it back.
What would be great if someone could fill in the blanks for me, or
point me to somewhere that does:
if fork
# UDP Server
server = UDPSocket.open
server.bind 'localhost', 12345
while (message, sender = server.recvfrom(64))
puts "We received: <#{message}> from #{sender[2]}"
return_message = "Hi there client!"
# Send response message here
end
else
# UDP Client
client = UDPSocket.open
client.connect 'localhost', 12345
client.puts "Hello Server!"
# assert that we got "Hi there client!" back
end
···
On 7/6/05, Joe Van Dyk <joevandyk@gmail.com> wrote:
I'm having problems creating a UDP socket that listens for messages on
a port and (sometimes) sends messages back to the original sender of
the message.
I can receive a message over the UDP socket fine, I'm just not sure
about how to know where to send the message back, and how to properly
send it back.
What would be great if someone could fill in the blanks for me, or
point me to somewhere that does:
Untested:
if fork
# UDP Server
server = UDPSocket.open
server.bind 'localhost', 12345
while (message, sender = server.recvfrom(64))
puts "We received: <#{message}> from #{sender[2]}"
return_message = "Hi there client!"
# Send response message here
# UDP Client
client = UDPSocket.open
client.connect 'localhost', 12345
client.puts "Hello Server!"
# assert that we got "Hi there client!" back
end
See UDPSocket#send in the Pickax.
Guillaume.
···
On Thu, 2005-07-07 at 05:21 +0900, Joe Van Dyk wrote:
On 7/6/05, Joe Van Dyk <joevandyk@gmail.com> wrote:
> I'm having problems creating a UDP socket that listens for messages on
> a port and (sometimes) sends messages back to the original sender of
> the message.
>
> I can receive a message over the UDP socket fine, I'm just not sure
> about how to know where to send the message back, and how to properly
> send it back.
>
> Thanks,
> Joe
>
On 7/6/05, Guillaume Marcais <guslist@free.fr> wrote:
On Thu, 2005-07-07 at 05:21 +0900, Joe Van Dyk wrote:
> What would be great if someone could fill in the blanks for me, or
> point me to somewhere that does:
Untested:
> if fork
> # UDP Server
> server = UDPSocket.open
> server.bind 'localhost', 12345
> while (message, sender = server.recvfrom(64))
> puts "We received: <#{message}> from #{sender[2]}"
>
> return_message = "Hi there client!"
> # Send response message here
server.send(return_message, 0, sender[2], sender[1])
> end
> else
>
> # UDP Client
> client = UDPSocket.open
> client.connect 'localhost', 12345
> client.puts "Hello Server!"
> # assert that we got "Hi there client!" back
> end
See UDPSocket#send in the Pickax.
Guillaume.
> On 7/6/05, Joe Van Dyk <joevandyk@gmail.com> wrote:
> > I'm having problems creating a UDP socket that listens for messages on
> > a port and (sometimes) sends messages back to the original sender of
> > the message.
> >
> > I can receive a message over the UDP socket fine, I'm just not sure
> > about how to know where to send the message back, and how to properly
> > send it back.
> >
> > Thanks,
> > Joe
> >
>
If I need to send a message that's greater than 64KB back, is there
some standard Ruby way of doing so? (64KB seems to be the maximum
packet size)
···
On 7/6/05, Joe Van Dyk <joevandyk@gmail.com> wrote:
Seems to work great, thanks!
On 7/6/05, Guillaume Marcais <guslist@free.fr> wrote:
> On Thu, 2005-07-07 at 05:21 +0900, Joe Van Dyk wrote:
> > What would be great if someone could fill in the blanks for me, or
> > point me to somewhere that does:
>
> Untested:
>
> > if fork
> > # UDP Server
> > server = UDPSocket.open
> > server.bind 'localhost', 12345
> > while (message, sender = server.recvfrom(64))
> > puts "We received: <#{message}> from #{sender[2]}"
> >
> > return_message = "Hi there client!"
> > # Send response message here
> server.send(return_message, 0, sender[2], sender[1])
> > end
> > else
> >
> > # UDP Client
> > client = UDPSocket.open
> > client.connect 'localhost', 12345
> > client.puts "Hello Server!"
> > # assert that we got "Hi there client!" back
> > end
>
> See UDPSocket#send in the Pickax.
>
> Guillaume.
>
> > On 7/6/05, Joe Van Dyk <joevandyk@gmail.com> wrote:
> > > I'm having problems creating a UDP socket that listens for messages on
> > > a port and (sometimes) sends messages back to the original sender of
> > > the message.
> > >
> > > I can receive a message over the UDP socket fine, I'm just not sure
> > > about how to know where to send the message back, and how to properly
> > > send it back.
> > >
> > > Thanks,
> > > Joe
> > >
> >
>
>
>
If I need to send a message that's greater than 64KB back, is there
some standard Ruby way of doing so? (64KB seems to be the maximum
packet size)
No. That's the maximum size of a UDP packet, and since UDP is a
datagram protocol, there is no mechanism to say 'this packet is a
continuation of that packet' at the UDP level. You'd have to do so at
a higher level.
Are there any 'tricks' that I can use to make sending data messages
larger than 64KB back over UDP? (i.e. any Ruby functions that will
break up a message into smaller chunks and then reassemble)
···
On 7/6/05, Yohanes Santoso <ysantoso-rubytalk@dessyku.is-a-geek.org> wrote:
Joe Van Dyk <joevandyk@gmail.com> writes:
> Related question:
>
> If I need to send a message that's greater than 64KB back, is there
> some standard Ruby way of doing so? (64KB seems to be the maximum
> packet size)
No. That's the maximum size of a UDP packet, and since UDP is a
datagram protocol, there is no mechanism to say 'this packet is a
continuation of that packet' at the UDP level. You'd have to do so at
a higher level.
Are there any 'tricks' that I can use to make sending data messages
larger than 64KB back over UDP? (i.e. any Ruby functions that will
break up a message into smaller chunks and then reassemble)
No. UDP really does not have the necessary features needed for
establishing a virtual-circuit (which is what you want).
You'd need to add the following at the very minimum:
Do the above, and you'll have TCP minus flow control, which begs the
question of why not use TCP in the first place. I don't know what your
requirements are, so I can't say, 'use TCP, don't use udp'.
There is a plethora of protocols over UDP that tries to emulate some
of TCP functionalities, like LEAP (lightweight & efficient application
protocols) (disclaimer: i was involved in development of LEAP
protocols), or a darling among the media industry: RTSP (Real Time
Streaming Protocol) Usually they were created due to the need of a
protocol that is 'lighter' than TCP but provides the reliability of a
virtual circuit; a compromise.
So, either use those protocols, or you'd have to make one yourself.
but you may just want to roll your own simple solution using sequence
numbers and retransmission.
Joe Van Dyk wrote:
···
Are there any 'tricks' that I can use to make sending data messages
larger than 64KB back over UDP? (i.e. any Ruby functions that will
break up a message into smaller chunks and then reassemble)
On 7/6/05, Yohanes Santoso <ysantoso-rubytalk@dessyku.is-a-geek.org> wrote:
Joe Van Dyk <joevandyk@gmail.com> writes:
Related question:
If I need to send a message that's greater than 64KB back, is there
some standard Ruby way of doing so? (64KB seems to be the maximum
packet size)
No. That's the maximum size of a UDP packet, and since UDP is a
datagram protocol, there is no mechanism to say 'this packet is a
continuation of that packet' at the UDP level. You'd have to do so at
a higher level.
Are there any 'tricks' that I can use to make sending data messages
larger than 64KB back over UDP? (i.e. any Ruby functions that will
break up a message into smaller chunks and then reassemble)
Are you sure TCP is inappropriate for your application?
Off-hand I'm not aware of Ruby libraries to do what you're
asking, but I just wanted to mention, if you tackle it
yourself: Remember UDP packets may arrive at the destionation
out of sequence; the same packet may arrive more than once;
or not at all.