receive selectively from a DatagramSocket

L

Lorenzo Bettini

Hi

I'd like to receive a datagram packet through a DatagramSocket only from
a specific address:port;

is it possible to do so directly? Or should I program a sort of dispatcher?

many thanks in advance
Lorenzo

--
+-----------------------------------------------------+
| Lorenzo Bettini ICQ# lbetto, 16080134 |
| PhD in Computer Science |
| Dip. Sistemi e Informatica, Univ. di Firenze |
| Tel +39 055 4237441, Fax +39 055 4237437 |
| Florence - Italy (GNU/Linux User # 158233) |
| Home Page : http://www.lorenzobettini.it |
| http://music.dsi.unifi.it XKlaim language |
| http://www.lorenzobettini.it/purple Cover Band |
| http://www.gnu.org/software/src-highlite |
| http://www.gnu.org/software/gengetopt |
| http://www.lorenzobettini.it/software/gengen |
| http://www.lorenzobettini.it/software/doublecpp |
+-----------------------------------------------------+
 
J

John C. Bollinger

Lorenzo said:
I'd like to receive a datagram packet through a DatagramSocket only from
a specific address:port;

is it possible to do so directly? Or should I program a sort of
dispatcher?

Does not DatagramSocket.connect() do what you want?
 
L

Lorenzo Bettini

John said:
Does not DatagramSocket.connect() do what you want?

what I would like to do is a sort of ServerSocket/Socket pair but with
DatagramSocket.

connect ensures that once I'm connected to a specific IP:port then I'm
guaranteed to receive only packets from that IP:port, and for
client-side that's OK.

But what about the server? If I do connect also on the server then the
server won't be able to use that specific IP:port for communicating with
other clients (while with server socket I accept many connections
listening on the same port). Or am I missing something?

Of course, this can be programmed (with a sort of demultiplexer) but I
was wondering if there's already an implemented way to do so.

Lorenzo

--
+-----------------------------------------------------+
| Lorenzo Bettini ICQ# lbetto, 16080134 |
| PhD in Computer Science |
| Dip. Sistemi e Informatica, Univ. di Firenze |
| Tel +39 055 4237441, Fax +39 055 4237437 |
| Florence - Italy (GNU/Linux User # 158233) |
| Home Page : http://www.lorenzobettini.it |
| http://music.dsi.unifi.it XKlaim language |
| http://www.lorenzobettini.it/purple Cover Band |
| http://www.gnu.org/software/src-highlite |
| http://www.gnu.org/software/gengetopt |
| http://www.lorenzobettini.it/software/gengen |
| http://www.lorenzobettini.it/software/doublecpp |
+-----------------------------------------------------+
 
J

John C. Bollinger

Lorenzo said:
what I would like to do is a sort of ServerSocket/Socket pair but with
DatagramSocket.

connect ensures that once I'm connected to a specific IP:port then I'm
guaranteed to receive only packets from that IP:port, and for
client-side that's OK.

But what about the server? If I do connect also on the server then the
server won't be able to use that specific IP:port for communicating with
other clients (while with server socket I accept many connections
listening on the same port). Or am I missing something?

Of course, this can be programmed (with a sort of demultiplexer) but I
was wondering if there's already an implemented way to do so.

Oh, I see what you're getting at.

DatagramSockets work differently than Sockets, because the underlying
socket types and protocols work differently. In particular, datagram
protocols (used by DatagramSockets) are not connection-oriented and do
not provide any guarantees related to packet delivery, whereas stream
protocols (used by Sockets and ServerSockets) are connection-oriented
and provide guaranteed in-order delivery of all data sent.
DatagramSockets do not provide a facility similar to
ServerSocket.accept(), because POSIX does not specify that the
underlying system sockets for datagram protocols support such a feature.
That's also why there's no such thing as a DatagramServerSocket.

Datagram-based services that need to hold a conversation with clients
(rather than operating in single request / single response mode) need to
handle conversational in an application-dependant way. There is
considerable parallel to HTTP and various mechanisms for HTTP servers,
cooperating with their clients, to thread multiple requests together
into sessions. In particular, it is naive to assume without other
evidence that a request from some particular address and port is part
of the same conversation as any previous request from that address /
port pair. (Even before you start worrying about malicious software.)
Datagram-based services that want to hold a conversation typically also
need to worry about handling dropped datagrams and out-of-order datagram
delivery; these are handled at protocol level for stream-based services.
 
L

Lorenzo Bettini

John said:
Datagram-based services that need to hold a conversation with clients
(rather than operating in single request / single response mode) need to
handle conversational in an application-dependant way. There is

OK, I suspected that (indeed I already started to work on this), but I
wanted to be sure :)

thanks
Lorenzo

--
+-----------------------------------------------------+
| Lorenzo Bettini ICQ# lbetto, 16080134 |
| PhD in Computer Science |
| Dip. Sistemi e Informatica, Univ. di Firenze |
| Florence - Italy (GNU/Linux User # 158233) |
| Home Page : http://www.lorenzobettini.it |
| http://music.dsi.unifi.it XKlaim language |
| http://www.lorenzobettini.it/purple Cover Band |
| http://www.gnu.org/software/src-highlite |
| http://www.gnu.org/software/gengetopt |
| http://www.lorenzobettini.it/software/gengen |
| http://www.lorenzobettini.it/software/doublecpp |
+-----------------------------------------------------+
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,900
Latest member
Nell636132

Latest Threads

Top