Discussion:
Searching a library for client server game programming with SDL
Altair Linux
2009-09-08 05:50:47 UTC
Permalink
Hello list,

I found SDL_net, and I read some documents about sockets, what is the name
of the most habitual library for this?. I use C/C++ under Linux.
Donny Viszneki
2009-09-08 13:24:09 UTC
Permalink
I've heard enet is reasonable

http://enet.bespin.org/
Post by Altair Linux
Hello list,
I found SDL_net, and I read some documents about sockets, what is the name
of the most habitual library for this?. I use C/C++ under Linux.
_______________________________________________
SDL mailing list
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
--
http://codebad.com/
Micah Brening
2009-09-08 22:40:13 UTC
Permalink
Hello list,I found SDL_net, and I read some documents about sockets, what is
the name of the most habitual library for this?. I use C/C++ under Linux.

SDL_Net is good for the most part. If you want to use UDP you'll have to
implement your own transmission control and serialization.

ENet is good, but is UDP only. I'm not certain if it supports Game Lobby
Discovery (broadcasting)

I hear Raknet is good. Haven't used it though.

I WISH I could get grapple to work on windows, but the requirement of openssh
has messed that up for me. (never had luck with openssh on mingw32)
Kenneth Bull
2009-09-08 22:50:49 UTC
Permalink
Post by Micah Brening
Hello list,I found SDL_net, and I read some documents about sockets, what is
the name of the most habitual library for this?. I use C/C++ under Linux.
SDL_Net is good for the most part.  If you want to use UDP you'll have to
implement your own transmission control and serialization.
ENet is good, but is UDP only.  I'm not certain if it supports Game Lobby
Discovery (broadcasting)
I hear Raknet is good.  Haven't used it though.
I WISH I could get grapple to work on windows, but the requirement of openssh
has messed that up for me.  (never had luck with openssh on mingw32)
ENet includes a portability wrapper for socket APIs. That'll help even for TCP.
They have their own mailing list and IRC channel if you need help or
want more info on features.
Altair Linux
2009-09-09 06:07:35 UTC
Permalink
I don't know about this.

I am in a personal proyect in a future version (I don't how many time in the
future) I need to create a client - server comunication. I read only a basic
tutorial about sockets in linux. This is the reason I searching any library.

I read the documentation of sdl_net but I think is maybe confused. I not
understand how to put a host, a port number and data to send, etc.
Hieu Le Trung
2009-09-09 06:54:43 UTC
Permalink
1) SDLNet_Init is to initialize the SDL_net library

2) SDLNet_ResolveHost is to resolve hostname to IP

3) SDLNet_TCP_Open is to open a connection using the IP in step 2

4) SDLNet_TCP_Send is to send data



You can find in the SDL net documentation
http://jcatki.no-ip.org:8080/SDL_net/



From: sdl-***@lists.libsdl.org [mailto:sdl-***@lists.libsdl.org]
On Behalf Of Altair Linux
Sent: Wednesday, September 09, 2009 1:08 PM
To: A list for developers using the SDL library. (includes SDL-announce)
Cc: ***@libsdl.org
Subject: Re: [SDL] Searching a library for client server game
programmingwith SDL



I don't know about this.

I am in a personal proyect in a future version (I don't how many time in
the future) I need to create a client - server comunication. I read only
a basic tutorial about sockets in linux. This is the reason I searching
any library.

I read the documentation of sdl_net but I think is maybe confused. I not
understand how to put a host, a port number and data to send, etc.
Kenneth Bull
2009-09-09 07:05:10 UTC
Permalink
Post by Altair Linux
I read the documentation of sdl_net but I think is maybe confused. I not
understand how to put a host, a port number and data to send, etc.
After SDL_Init(), do this:

if (SDLNet_Init() == -1) {
printf("Error initializing SDL_Net: %s\n", SDLNet_GetError());
exit(1);
}

Before SDL_Quit(), do this:

SDLNet_Quit();

To get an IP address from a host name, do this (for www.example.com:80):

IPaddress ipaddress;
if (SDLNet_ResolveHost(&ipaddress, "www.example.com", 80) == -1) {
printf("Unable to resolve host address: %s\n", SDLNet_GetError());
exit(2);
}

To open a TCP connection to an IP address, do this:

TCPsocket tcpsock;
tcpsock=SDLNet_TCP_Open(&ipaddress);
if (!tcpsock) {
printf("Unable to connect to host: %s\n", SDLNet_GetError());
exit(3);
}

To send data over a TCP connection, do this:

char* data = "hello world", tmp;
int length = strlen(data)+1;
int bytessent = 0, result;
tmp = data;

do {
result = SDLNet_TCP_Send(tcpsock, tmp, length - bytessent);
if (result == 0) {
printf("TCP connection closed unexpectedly\n");
exit(4);
}
bytessent += result;
tmp += result;
} while (bytessent < length);

To check if data is available from a TCP connection, do this:

if (SDLNet_SocketReady(tcpsock)) {
// do stuff
}

To receive data from a TCP connection, do this:

int buffer_size = 1024, bytesreceived;
char buffer[buffer_size+1];
bytesreceived = SDLNet_TCP_Recv(tcpsock, buffer, buffer_size);
if (bytesreceived < 0) {
printf("Error receiving data: %s\n", SDLNet_GetError());
exit(5);
}
if (bytesreceived == 0) {
printf("TCP connection closed unexpectedly\n");
exit(6);
}
buffer[bytesreceived] = '\0';
printf("Received data: %s\n", buffer);

To close a TCP connection, do this:

SDLNet_TCP_Close(tcpsock);

you can find additional documentation here:
http://www.libsdl.org/cgi/docwiki.cgi/SDL_net
Brian
2009-09-09 08:19:56 UTC
Permalink
Hi.

If you haven't, do read Beej's network guide. It is a great
introduction to network programming. http://beej.us/guide/bgnet/

If you keep the SDL_net API documentation open
(http://www.libsdl.org/cgi/docwiki.cgi/SDL_net) you should be able to
translate the calls between the raw socket API and SDL_net (most of
the time, SDL_net is easier =).
Post by Altair Linux
I don't know about this.
I am in a personal proyect in a future version (I don't how many time in the
future) I need to create a client - server comunication. I read only a basic
tutorial about sockets in linux. This is the reason I searching any library.
I read the documentation of sdl_net but I think is maybe confused. I not
understand how to put a host, a port number and data to send, etc.
Christoph Nelles
2009-09-09 11:33:33 UTC
Permalink
Hi,

i haven't understood exactly what you are seeking, but with basic
knowledge how the socket system works, you won't get far. This is a
discussion you might be interested in:
http://stackoverflow.com/questions/118945/best-c-c-network-library

A few months ago i searched for a multi-platform OSS C++ network library
with IPv6 support (SDL_net lacks IPv6), but haven't got time to evaluate my
findings. Not mentioned in the discussion above are
Endpoint: http://endpoint.sourceforge.net/
Simple and Fast Multimedia Library: http://www.sfml-dev.org/

Btw. if RAKnet is really UDP-only then forget it. UDP is fine and fast
within LANs, but if you plan to make your game playable on the internet,
you won't get far. UDP is not very NAT/Masquerading friendly.
Post by Altair Linux
Hello list,
I found SDL_net, and I read some documents about sockets, what is the name
of the most habitual library for this?. I use C/C++ under Linux.
--
Christoph Nelles

E-Mail : ***@evilazrael.de
Jabber : ***@evilazrael.net ICQ : 78819723

PGP-Key : ID 0x424FB55B on subkeys.pgp.net
or http://evilazrael.net/pgp.txt
Brian
2009-09-09 11:42:18 UTC
Permalink
Most fast paced online games use UDP. TCP has some properties which
make it less suitable for real time transport. Unless you are talking
about hosting issues? Most NATs allow port forwarding for UDP and TCP,
so I don't see how TCP would be superior?

On Wed, Sep 9, 2009 at 12:33 PM, Christoph
Post by Christoph Nelles
Hi,
Btw. if RAKnet is really UDP-only then forget it. UDP is fine and fast
within LANs, but if you plan to make your game playable on the internet,
you won't get far. UDP is not very NAT/Masquerading friendly.
Christoph Nelles
2009-09-09 11:54:12 UTC
Permalink
Post by Brian
Most fast paced online games use UDP. TCP has some properties which
make it less suitable for real time transport. Unless you are talking
about hosting issues? Most NATs allow port forwarding for UDP and TCP,
so I don't see how TCP would be superior?
You need:
- Understanding what NAT/Masquerading is
- Access/Right/Knowledge to/for/of the router
- A router which is capable of the necessary changes
- Information about required ports, etc
- Games often use fixed ports, making it impossible to use more than a
client behind a router
- as a developer. Willingness to accept lost packets and design a fault
tolerant software

Not many consumers meet the above requirements. I estimate 95 - 99% of the
standard mainstream can't do this. Take DirectPlay, it's a nightmare if you
are in charge of a router.
Post by Brian
On Wed, Sep 9, 2009 at 12:33 PM, Christoph
Post by Christoph Nelles
Hi,
Btw. if RAKnet is really UDP-only then forget it. UDP is fine and fast
within LANs, but if you plan to make your game playable on the internet,
you won't get far. UDP is not very NAT/Masquerading friendly.
--
Christoph Nelles

E-Mail : ***@evilazrael.de
Jabber : ***@evilazrael.net ICQ : 78819723

PGP-Key : ID 0x424FB55B on subkeys.pgp.net
or http://evilazrael.net/pgp.txt
liam mail
2009-09-09 11:44:12 UTC
Permalink
Post by Christoph Nelles
Hi,
i haven't understood exactly what you are seeking, but with basic
knowledge how the socket system works, you won't get far. This is a
http://stackoverflow.com/questions/118945/best-c-c-network-library
A few months ago i searched for a multi-platform OSS C++ network library
with IPv6 support (SDL_net lacks IPv6), but haven't got time to evaluate my
findings. Not mentioned in the discussion above are
Endpoint: http://endpoint.sourceforge.net/
Simple and Fast Multimedia Library: http://www.sfml-dev.org/
Btw. if RAKnet is really UDP-only then forget it. UDP is fine and fast
within LANs, but if you plan to make your game playable on the internet,
you won't get far. UDP is not very NAT/Masquerading friendly.
Post by Altair Linux
Hello list,
I found SDL_net, and I read some documents about sockets, what is the
name
Post by Altair Linux
of the most habitual library for this?. I use C/C++ under Linux.
--
Christoph Nelles
PGP-Key : ID 0x424FB55B on subkeys.pgp.net
or http://evilazrael.net/pgp.txt
_______________________________________________
SDL mailing list
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
"Btw. if RAKnet is really UDP-only then forget it. UDP is fine and fast
within LANs, but if you plan to make your game playable on the internet,
you won't get far. UDP is not very NAT/Masquerading friendly."
Please stop spreading nonsense like this. UDP is used in __nearly__ all fast
paced action games on the pc. Raknet has a reliability layer so even if it
does not support TCP it can emulate it.
Christoph Nelles
2009-09-09 12:00:23 UTC
Permalink
Hi,
Post by liam mail
Please stop spreading nonsense like this. UDP is used in __nearly__ all fast
paced action games on the pc. Raknet has a reliability layer so even if it
does not support TCP it can emulate it.
Name a few. Oh, leave every one out, which you can't play because you are
in a masqueraded LAN often found in in dormatories.
--
Christoph Nelles

E-Mail : ***@evilazrael.de
Jabber : ***@evilazrael.net ICQ : 78819723

PGP-Key : ID 0x424FB55B on subkeys.pgp.net
or http://evilazrael.net/pgp.txt
liam mail
2009-09-09 12:12:27 UTC
Permalink
Post by Christoph Nelles
Hi,
Post by liam mail
Please stop spreading nonsense like this. UDP is used in __nearly__ all fast
paced action games on the pc. Raknet has a reliability layer so even if
it
Post by liam mail
does not support TCP it can emulate it.
Name a few. Oh, leave every one out, which you can't play because you are
in a masqueraded LAN often found in in dormatories.
--
Christoph Nelles
PGP-Key : ID 0x424FB55B on subkeys.pgp.net
or http://evilazrael.net/pgp.txt
_______________________________________________
SDL mailing list
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org
Let me first point out this is the SDL mailing list.
Secondly are you abaraba? He has been doing the rounds lately
http://gafferongames.com/2009/09/04/the-return-of-the-timestep-crusader/
Thirdly your need for me to mention which games use UDP indicates you have
no knowledge on the matter, if you would like to explore this more via a
conversation please post to the gamedev.net network forum, the igda network
mailing list or any other game networking forum/list and I am sure people
will be more than happy to dispel your beliefs. Remember that I am saying
UDP is used for fast paced against games, do you think TCP is good for this
type of game? I mean a client is going to sit there and wait whilst the
kernel buffers your messages because one went a stray? Not forgetting that
this missing message may not longer be of any relavance to the game state. I
am not saying TCP can not be used only it is the exsecption to the __norm__.
Finally you do you mention DirectPlay an API which has not been available in
an SDK release for over two years because .... well ... it was pathetic.
Brian
2009-09-09 12:13:13 UTC
Permalink
Post by Christoph Nelles
Understanding what NAT/Masquerading is
I have that =)
Post by Christoph Nelles
- Access/Right/Knowledge to/for/of the router
- A router which is capable of the necessary changes
This is true. But TCP doesn't help you here
Post by Christoph Nelles
- Information about required ports, etc
Not usually a problem - netstat etc will tell you what ports a server uses.
Post by Christoph Nelles
- Games often use fixed ports, making it impossible to use more than a
client behind a router

That depends on the program, its not a universal rule. If you are
making your own game you can make configurable ports.
Post by Christoph Nelles
as a developer. Willingness to accept lost packets and design a fault
tolerant software

If you are using UDP, this is already part of the contract
Post by Christoph Nelles
Name a few. Oh, leave every one out, which you can't play because you are
in a masqueraded LAN often found in in dormatories.
The question remains - TCP solves this problem how? What is the alternative?
Gregory Smith
2009-09-09 13:18:40 UTC
Permalink
Post by Christoph Nelles
Btw. if RAKnet is really UDP-only then forget it. UDP is fine and fast
within LANs, but if you plan to make your game playable on the internet,
you won't get far. UDP is not very NAT/Masquerading friendly.
Excuse me? You've got a way better chance of getting UDP packets through a
NAT router, thanks to STUN/TURN/ICE. I would guess UDP is the norm for
online first person shooters.

Gregory

Loading...