Networking question

A question for ya:

There are two ways to handle connectionless datagram sockets:

  1. Virtualize the socket into multiple communication channels, based
    on source address.
  2. Return any packets that have arrived on the socket.

The answer depends on the needs of your application, but I was wondering
how useful option 1 would be to you.

This means that you could treat a datagram socket with multiple packet
sources as virtual sockets, each with it’s unique source address.
It would act just like connection-oriented sockets with unreliable delivery.

See ya!
-Sam Lantinga (slouken at devolution.com)–
Author of Simple DirectMedia Layer -
http://www.devolution.com/~slouken/SDL/

I use option #1 in my networking layer.

  • Dan> -----Original Message-----

From: Sam Lantinga [SMTP:slouken at devolution.com]
Sent: Monday, October 26, 1998 9:24 AM
To: sdl at surfnetcity.com.au
Cc: @Kegel_Dan
Subject: Networking question

A question for ya:

There are two ways to handle connectionless datagram sockets:

  1. Virtualize the socket into multiple communication channels, based
    on source address.
  2. Return any packets that have arrived on the socket.

The answer depends on the needs of your application, but I was wondering
how useful option 1 would be to you.

This means that you could treat a datagram socket with multiple packet
sources as virtual sockets, each with it’s unique source address.
It would act just like connection-oriented sockets with unreliable
delivery.

See ya!
-Sam Lantinga (slouken at devolution.com)


Author of Simple DirectMedia Layer -
http://www.devolution.com/~slouken/SDL/

Sam Lantinga writes:

A question for ya:

There are two ways to handle connectionless datagram sockets:

Just an unrelated question, why not use CORBA for the networking ?

Phil

Just an unrelated question, why not use CORBA for the networking ?

While CORBA is well suited for database and transaction systems, it’s
too high level to use as the abstraction layer for networking games.
Basically, real-time games need the following:

  • Millisecond accuracy and overhead.
  • Fast error detection and recovery.
  • Broadcast or multicast support.

Not to mention the portabilitity aspects – CORBA is portable, but it’s
simply not installed on most machines.

Matt

/* Matt Slot, Bitwise Operator * One box, two box, yellow box, blue box. *

Matt Slot writes:

While CORBA is well suited for database and transaction systems, it’s
too high level to use as the abstraction layer for networking games.
Basically, real-time games need the following:

  • Millisecond accuracy and overhead.
  • Fast error detection and recovery.
  • Broadcast or multicast support.

Not to mention the portabilitity aspects – CORBA is portable, but it’s
simply not installed on most machines.

Good points. However, when the network aspects will come I think I’ll
use CORBA as a first try. This way I can say that I know CORBA, it
always looks goods on resume :wink:

Is a network aware SDL planned in the not so fare future ?

Phil

PS Where is the mail archive ?

Is a network aware SDL planned in the not so fare future ?

No, not really. There has just been enough demand for cross-platform
networking with SDL that I will include an example library with the
demos archive. :slight_smile:

If it becomes very useful, it may join the SDL code.

PS Where is the mail archive ?

Michael? Where is that mail archive and search engine? :slight_smile:

See ya!
-Sam Lantinga (slouken at devolution.com)–
Author of Simple DirectMedia Layer -
http://www.devolution.com/~slouken/SDL/

Just an unrelated question, why not use CORBA for the networking ?

While CORBA is well suited for database and transaction systems, it’s
too high level to use as the abstraction layer for networking games.
Basically, real-time games need the following:

  • Millisecond accuracy and overhead.
  • Fast error detection and recovery.
  • Broadcast or multicast support.

For these same reasons TCP is not necessarily the optimal choice for
most game networking. TCP stands for Transmission Control Protocol,
and as you might guess from the name, has a fair bit of error correction
and dynamic bandwidth adjusting built into it. This presents overhead
that you won’t necessarily want in your game.

UDP is a very good choice for most real-time games, as it is datagram based
with almost zero protocol overhead. The disadvantages of it are that
packets can arrive out-of-order, or never arrive at all. This can be
worked around using a variety of methods, including sort of patching
things up after inconsistencies occur. You can see this in Diablo,
as creatures suddenly “warp” to a different spot, or someone suddenly
appears in a different place, already dying.

I’m redoing the API for the networking library, so that it will have
two separate APIs for TCP and UDP, taking advantage of the characteristics
of each protocol. Both will be available, depending on your needs:

(This is still really rough)

TCP:
create(server/remote)
select(server/remote)
accept(server)
send(remote, data, len)
recv(remote, data, maxlen)
close(server/remote)

UDP:
initialize(localport)
channel = open(address)
read(packet, timeout)
readv(packets, npackets, timeout)
getpacketaddress(packet)
write(channels, packet);
writev(channels, packets, npackets);
close(channel)
deinitialize()

See ya!
-Sam Lantinga (slouken at devolution.com)–
Author of Simple DirectMedia Layer -
http://www.devolution.com/~slouken/SDL/

IMHO timeout on read is harmful. Make it totally nonblocking…
unless you’re requiring them to have a multithreaded environment.

Also, read = readv(1, …), may as well make it a macro :slight_smile:

  • Dan> -----Original Message-----

From: Sam Lantinga [SMTP:slouken at devolution.com]
Sent: Monday, October 26, 1998 2:34 PM
To: sdl at surfnetcity.com.au
Cc: @Kegel_Dan
Subject: Re: [SDL] Networking question

Just an unrelated question, why not use CORBA for the networking ?

While CORBA is well suited for database and transaction systems, it’s
too high level to use as the abstraction layer for networking games.
Basically, real-time games need the following:

  • Millisecond accuracy and overhead.
  • Fast error detection and recovery.
  • Broadcast or multicast support.

For these same reasons TCP is not necessarily the optimal choice for
most game networking. TCP stands for Transmission Control Protocol,
and as you might guess from the name, has a fair bit of error correction
and dynamic bandwidth adjusting built into it. This presents overhead
that you won’t necessarily want in your game.

UDP is a very good choice for most real-time games, as it is datagram
based
with almost zero protocol overhead. The disadvantages of it are that
packets can arrive out-of-order, or never arrive at all. This can be
worked around using a variety of methods, including sort of patching
things up after inconsistencies occur. You can see this in Diablo,
as creatures suddenly “warp” to a different spot, or someone suddenly
appears in a different place, already dying.

I’m redoing the API for the networking library, so that it will have
two separate APIs for TCP and UDP, taking advantage of the characteristics
of each protocol. Both will be available, depending on your needs:

(This is still really rough)

TCP:
create(server/remote)
select(server/remote)
accept(server)
send(remote, data, len)
recv(remote, data, maxlen)
close(server/remote)

UDP:
initialize(localport)
channel = open(address)
read(packet, timeout)
readv(packets, npackets, timeout)
getpacketaddress(packet)
write(channels, packet);
writev(channels, packets, npackets);
close(channel)
deinitialize()

See ya!
-Sam Lantinga (slouken at devolution.com)


Author of Simple DirectMedia Layer -
http://www.devolution.com/~slouken/SDL/

I’m finding fewer nits to pick :slight_smile:
But one BIG nit is that you might still static data, e.g. the channels
array.
That should be a member variable.
Every one of these functions should take a this pointer
as its first argument (except the constructor).
This allows that all-important ability to have several copies
of the library running in same program at same time.

BTW, NAT support may require wierd functions like
sdlnet_setSecondaryAddress(handle, address)
so when a game doesn’t know which of the two
addresses (original and translated) a game behind a NAT
is going to show up as, it can still recognize the packet
as coming from that handle. Or something like that :slight_smile:

  • Dan> -----Original Message-----

From: Sam Lantinga [SMTP:slouken at devolution.com]
Sent: Monday, October 26, 1998 3:02 PM
To: Kegel, Dan
Subject: Re: [SDL] Networking question

IMHO timeout on read is harmful. Make it totally nonblocking…
unless you’re requiring them to have a multithreaded environment.

Good call.

Also, read = readv(1, …), may as well make it a macro :slight_smile:

Yup, that was the plan. :slight_smile:

Does the API look pretty good?

See ya!
-Sam Lantinga (slouken at devolution.com)


Author of Simple DirectMedia Layer -
http://www.devolution.com/~slouken/SDL/

duh, my send loops look more like
while (I feel like sending a packet)
enqueue udp packet
is dat wrong?

The receive loop looks a lot simpler - just select on the one socket.

  • Dan> -----Original Message-----

From: Sam Lantinga [SMTP:slouken at devolution.com]
Sent: Monday, October 26, 1998 10:55 AM
To: Kegel, Dan
Subject: Re: Networking question

I use option #1 in my networking layer.

How do you handle select() on a single file descriptor for multiple
virtual channels?

Like this:

while ( UDP socket ready )
Enqueue UDP packet on virtual channel

?
See ya!
-Sam Lantinga (slouken at devolution.com)


Author of Simple DirectMedia Layer -
http://www.devolution.com/~slouken/SDL/

I’d say don’t let them select() on individual channels.
Does that help?

  • dan> -----Original Message-----

From: Sam Lantinga [SMTP:slouken at devolution.com]
Sent: Monday, October 26, 1998 11:06 AM
To: Kegel, Dan
Subject: Re: Networking question

duh, my send loops look more like
while (I feel like sending a packet)
enqueue udp packet
is dat wrong?

The receive loop looks a lot simpler - just select on the one socket.

I was talking about receiving. I’m trying to map between virtual channels
and UDP file descriptors, and it seems like it takes way more overhead
than
it should. Am I doing it the dumb way? :slight_smile:

See ya!
-Sam Lantinga (slouken at devolution.com)


Author of Simple DirectMedia Layer -
http://www.devolution.com/~slouken/SDL/

I just say
while ( getpacket(buf, &len, &src) ) {
handle packet from channel ‘src’
}

I don’t queue anything. I do look up the channel it came on for them,
though.
But if they want to support NAT’s, there might be several addresses on
the packet from a given source, so it’s challenging to do the lookup right.

  • Dan> -----Original Message-----

From: Sam Lantinga [SMTP:slouken at devolution.com]
Sent: Monday, October 26, 1998 11:25 AM
To: Kegel, Dan
Subject: Re: Networking question

I’d say don’t let them select() on individual channels.
Does that help?

Yes, but then how do you do this:

for channel in some channels
do if channel ready for read
then read on channel
done

Do you just say:

SuckIncomingPackets()
for channel in some channels
do if packet queued on channel
then dequeue packet
done

?

Hum. I’m leaning towards not having virtual UDP channels.
That way you completely eliminate the internal queues and associated
overhead.
If the application needs them, then it can do the following:

while read packet
do for address in known addresses
do if address == packet address
then channel = channels[address]
done
if channel
then queue packet on channel
done

Your Opinion, por favor? O Guru of networks? :slight_smile:

See ya!
-Sam Lantinga (slouken at devolution.com)


Author of Simple DirectMedia Layer -
http://www.devolution.com/~slouken/SDL/

The magic boxes that let you share cable modems.
Linux has a broken NAT implementation in Masq.
It always assigns a new global address even
when you try to reuse a UDP port to send to a 2nd destination.
I think it’ll get fixed sooner or later.

  • Dan> -----Original Message-----

From: Sam Lantinga [SMTP:slouken at devolution.com]
Sent: Monday, October 26, 1998 11:45 AM
To: Kegel, Dan
Subject: Re: Networking question

I don’t queue anything. I do look up the channel it came on for them,
though.
But if they want to support NAT’s, there might be several addresses on
the packet from a given source, so it’s challenging to do the lookup
right.

What exactly are NAT’s? Network Address Translations? What are those?

See ya!
-Sam Lantinga (slouken at devolution.com)


Author of Simple DirectMedia Layer -
http://www.devolution.com/~slouken/SDL/

PS Where is the mail archive ?

Michael? Where is that mail archive and search engine? :slight_smile:

Well, the archive is at http://mail.surfnetcity.com.au/archives/SDL/

There are currently 1269 messages (I recently fixed a 1k message problem, so
now there are 20 directories, each containing 100 messages)

As for a search engine, I just registered it on Altavista, and should be
indexed in a day or 2. (HINT: try searching for "SDL Mailing-list Archive"
with your query)On Mon, Oct 26, 1998 at 12:29:45PM -0800, Sam Lantinga wrote:


– Michael Samuel

UDP is a very good choice for most real-time games, as it is datagram based
with almost zero protocol overhead. The disadvantages of it are that
packets can arrive out-of-order, or never arrive at all. This can be
worked around using a variety of methods, including sort of patching
things up after inconsistencies occur.

is it possible to use both TCP and UDP ?
(like sending the important & not frequent packets through TCP and the other,
not-really-important ones through UDP?) i know that would (at least) require
opening two sockets instead of one.(?)

— tomaasz — Tomas Andrle — @Tomas_Andrle

is it possible to use both TCP and UDP ?

Yes, and several network libraries do that. It seems to work pretty well.

(like sending the important & not frequent packets through TCP and the,
other not-really-important ones through UDP?) i know that would (at least)
require opening two sockets instead of one.(?)

Right… “at least”.

On the client of client/server, it would be 2 sockets (1 UDP, 1 TCP to server).
On the server of client/server, it would be n+1 sockets (1 UDP, 1 TCP/player)
In a distributed model, there would likely be >2 sockets on each host.

On most UNIX flavors, this isn’t a big deal… but it does make for a network
hungry server. On other platforms, this may approach the built in networking
limits. YMMV.

Matt

/* Matt Slot, Bitwise Operator * One box, two box, yellow box, blue box. *

Sam Lantinga wrote:

Is a network aware SDL planned in the not so fare future ?

No, not really. There has just been enough demand for cross-platform
networking with SDL that I will include an example library with the
demos archive. :slight_smile:

If it becomes very useful, it may join the SDL code.

Please include it, because Almost all new game that uis more then just a
probe has a network implementation. And as you know, netwrokign is one of
the key of GPL and free-software, so people that program with it loves
Internet :-), so TCP/IP implementation in futur game will not be a plus, it
will be a necessity.–
Stephane Magnenat
stephane.magnenat at urbanet.ch

michael at surfnetcity.com.au writes:

Well, the archive is at http://mail.surfnetcity.com.au/archives/SDL/

There are currently 1269 messages (I recently fixed a 1k message problem, so
now there are 20 directories, each containing 100 messages)

As for a search engine, I just registered it on Altavista, and should be
indexed in a day or 2. (HINT: try searching for "SDL Mailing-list Archive"
with your query)

The archive is rather hard to browse through. Do you think you could
use something like MHonArc to archive the posts ?

I’m saying it’s hard because there are is no subject list of the
e-mails nor is there a threaded list.

You can get mhonarc from this site

http://www.oac.uci.edu/indiv/ehood/mhonarc.html

Phil

PS Altavista doesn’t know anything about SDL (at least not in the
first 10 queries out of 32750 possible match)

michael at surfnetcity.com.au writes:

Well, the archive is at http://mail.surfnetcity.com.au/archives/SDL/

There are currently 1269 messages (I recently fixed a 1k message problem, so
now there are 20 directories, each containing 100 messages)

As for a search engine, I just registered it on Altavista, and should be
indexed in a day or 2. (HINT: try searching for "SDL Mailing-list Archive"
with your query)

Yeah, I couldn’t find anything useful here either.

See ya!
-Sam Lantinga (slouken at devolution.com)–
Author of Simple DirectMedia Layer -
http://www.devolution.com/~slouken/SDL/

is it possible to use both TCP and UDP ?

Yes, just create another socket.On Tue, Oct 27, 1998 at 06:06:39PM +0100, Tomas Andrle wrote:


– Michael Samuel