TCP/IP communication for LAN and Internet games in Linux?

Linux specific questions.
axlucas
Posts: 3
Joined: Apr 08, 2014 23:37

TCP/IP communication for LAN and Internet games in Linux?

Postby axlucas » Apr 08, 2014 23:51

Hi, guys! I've been searching in the forum and there are several threads having to do with this, but I haven't found one that answers exactly what I need to know.

What I want to do is a programme that can communicate at least some 20 times per second (an action game, for example). The amount of information I want to transfer is relatively small each time. I need to know what would be the best way to do this in FreeBasic so that preferably...
  • I can use the same method for both LAN and Internet transparently
  • I don't need a separate server to mediate the communication
  • I can easily port my programme to other platforms, with small changes

I have no experience with external libraries, so if you recommend me one, please give me a hint on how I can install it and call it from FreeBasic. I've had a hard time looking up such libraries on my own with Google :P
Thank you all very much in advance!
TJF
Posts: 3473
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Re: TCP/IP communication for LAN and Internet games in Linux

Postby TJF » Apr 10, 2014 6:54

Did you find / check out EGNP yet?

Another solution would be using the external library libpurple. You can compile your programme as a plugin for Pidgin and run it in parallel with a textchat, VIOP or VIDEO call.
badidea
Posts: 1401
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: TCP/IP communication for LAN and Internet games in Linux

Postby badidea » Apr 11, 2014 20:57

With 20 times a second, you probably need to go UDP instead of TCP.
I played with custom UDP messages a little bit. I have not really tried any libraries since I wanted to understand the basics.
axlucas
Posts: 3
Joined: Apr 08, 2014 23:37

Re: TCP/IP communication for LAN and Internet games in Linux

Postby axlucas » Apr 14, 2014 22:21

Badidea: Yes. Well, it doesn't have to be TCP/IP. I am really not very familiar with networks and communication. Last time I programmed something that could do anything similar, I used null-modem cable or LPT-to-LPT. Now I want to do things like they're supposed to now.
I prefer really knowing what is going on too, so if it's not necessary to use a library, better for me. Can you give me a hint on how to start? Where should I read more about UDP in my case? Remember I would like to make sure the program is portable to other OSs.

TJF: Libpurple is very interesting. It's not what I want in this case, but I will consider it for other projects. I didn't know about it and could be very useful. Thanks. EGNP looks more like what I'm looking for, but I don't understand German. I downloaded it and will take a look at the code.
TJF
Posts: 3473
Joined: Dec 06, 2009 22:27
Location: N47°, E15°
Contact:

Re: TCP/IP communication for LAN and Internet games in Linux

Postby TJF » Apr 15, 2014 5:51

axlucas wrote:EGNP looks more like what I'm looking for, but I don't understand German. I downloaded it and will take a look at the code.

AFAIK EGNP is based on TSNE (from the same author). Find an English API documentation at

pestery
Posts: 493
Joined: Jun 16, 2007 2:00
Location: Australia

Re: TCP/IP communication for LAN and Internet games in Linux

Postby pestery » Apr 15, 2014 10:56

If you want to try using sockets then you should check out Beej's Guide to Network Programming. It's a really good introduction to using sockets, good sense of humor, and the author was using Linux. The only thing it it's all written in C. I don't know if you've ported C code to FB before, but it's very easy once you get the hang of it.

Using sockets is easy enough. All the commands are super easy to port between Linux/Mac/Windows, just change your #include statements and if porting to Windows then just add an initial setup and final shutdown command. Also, the commands are straight forward and you can get something basic running pretty quick.

You mentioned maybe using a library. One thing I'll say is that if you can find a library that does exactly the same as what you want to do, it would probably be easier in the long run. However I can't offer any advice on network libraries because I haven't used any apart from the basic sockets that Beej describes.

Regarding TCP vs UDP, I'm not sure how much you know already. Feel free to skip the rest of this post if you know this stuff already.

TCP (Transmission Control Protocol) is intended for reliably sending a stream of data over a network. The data you send will arrive at the other end, just as it was sent. Or the connection will time-out. It's good for sending files, webpages, text chat, log-on data, game data for turn-based games and some strategy games that are slow paced, and any other data you can think of that must arrive, regardless of how long it takes. This does not mean TCP is slow, it is actually very fast, but is not designed for sending small packets of data at a rate of 20 packets a second. If sending small packets you'll actually only get about 5 packets a second, see Nagle's algorithm. TCP is good for "I just want to send data, I don't care how it works".

UDP (User Datagram Protocol) is intended for quickly firing packets of data across a network and hoping they arrive. UDT is an unreliable protocol, meaning that the data is not guaranteed to arrive at the other end. In reality 95% or more of the data does arrive as it should, however you still need to allow for the 5% which can arrive out of order, have more than one copy of the same data arrive, or have no data arrive at all. What UDP does is give you more direct control over the low level packets being send over the network. This can be both a good thing and a bad one. Instead of having to wait for old data to be sent before you can send new data, you can just discard the old data. Of course you also have to make a system to monitor your data and make sure the important stuff arrives. And you have to consider network congestion and not send too many small packets when you can combine them into fewer larger packets. Long story short, UDP gives you more control to do what you want, but you have to make the systems yourself that already exist in TCP if you want them.

I've been investigating UDP vs TCP for games for, well, for a few years now. You can make up your own mind, but what I have decided on is that for games you really need to use UDP. Only use TCP for games if ALL your data MUST arrive and your not expecting more than 5 packets per second. You can disable Nagle's algorithm, but you should try and avoid turning off key features of the protocol your using (just my opinion).

Anyway, that was a longer post than I intended to make. I hope you find it useful.
I can probably make a couple of example programs if you like. I'm getting a little rusty with networking so it might do me some good.
speedfixer
Posts: 350
Joined: Nov 28, 2012 1:27
Location: California

Re: TCP/IP communication for LAN and Internet games in Linux

Postby speedfixer » May 12, 2014 0:21

Hi, all. I have had the same question as axlucas.

UDP does seem to be the way to go - however ...

The general consensus is that ZeroMQ is the best. And there is a (very old) header distributed with FB. I tried. (Sure, I was newer at FB, then, and new at working at net stuff.)

I ended up working hard to learn nuts and bolts of net stuff. Beej's IS the best!
But it was easier to just take apart the networked tic-tac-toe game, learn, and make my own routines than figure out how to use ZMQ.

I asked before: has anyone used ZMQ with FB, and how is that done? Couldn't someone help us new people, here? While there are several libraries, and (I think) tutorials in German and Russian, I speak neither.

Even a seperate topic on the board just for networking questions?
I would have a million questions - others would also. I think many beginners would love to see this rather than load the general, beginner, etc topics with our beginner questions. (Maybe it is my own problem that I want to learn without just simply ask-ask-ask-ask.)

David
badidea
Posts: 1401
Joined: May 24, 2007 22:10
Location: The Netherlands

Re: TCP/IP communication for LAN and Internet games in Linux

Postby badidea » May 12, 2014 21:43

Sorry for the late reply, I'm not so active with FreeBASIC at the moment. Beej's guide is very usefull.
I played with non-blocking sockets to avoid the use of mutiple threads. See Section "7. Slightly Advanced Techniques" in Beej's Guide.
Or my attempt in FreeBASIC in 2010 here: viewtopic.php?t=16826&postdays=0&postorder=asc&start=14

Return to “Linux”

Who is online

Users browsing this forum: No registered users and 1 guest