Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411281 Posts in 69324 Topics- by 58380 Members - Latest Member: bob1029

March 28, 2024, 11:21:18 PM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Help with networking
Pages: 1 [2]
Print
Author Topic: Help with networking  (Read 2312 times)
qMopey
Level 6
*


View Profile WWW
« Reply #20 on: May 01, 2019, 01:48:49 PM »

Usually it is a good idea to run your entire game so it is owned by one thread.

You can have one thread (a different thread) that runs `select` on your sockets to get notified of new incoming packets. This thread simply pulls packets off of the sockets and queues them up. Each game instance, owned by one thread, has a queue of incoming packets. The select thread just pushes packets onto these queues. Each game instance pulls packets out of these queues whenever they are looking for new information (like once per update loop, via polling).

select should work pretty well up to a certain point in scale. I have no experience with scaling select really high, but personally I do not imagine it will cause problems for anyone on these forums. I do know other MMO games have used things like epoll/kqueue for Linux, or IOCP on Windows. I don't think you need to read into these strategies, but I'm just posting about them here for posterity at this point Smiley

For my game I'm using UDP, so I just have a dedicated thread that pulls data off of a single UDP socket and queues them up for other threads to consume. TCP is slightly more complicated since each connection will have a different socket, hence requiring something like `select`. C# definitely will have some kind of select function exposed. You will have to search for it, since I don't know C# very well.
Logged
Qwerku
Level 0
**


View Profile
« Reply #21 on: May 01, 2019, 02:05:17 PM »

If this is your first foray into networking with client/server architecture and you're looking into using C#, I would strongly recommend you look at Mirror and Telepathy made by vis2k.  Granted, much of that work is Unity based, but moving it away to straight C# would be pretty straightforward.  Mirror means you're only writing your code once, and it's implemented for both the server and the client.  I've created a game using Mirror (which was realtime), and the performance was great, and since it's server authoritative, all of my standard hacking/cheating attempts failed.

If your game is turn based, I really don't understand the reasoning behind moving to UDP.  TCP would make your life much, much easier.
Logged
pengu2
Level 0
**



View Profile WWW
« Reply #22 on: May 02, 2019, 07:11:20 AM »

If this is your first foray into networking with client/server architecture and you're looking into using C#, I would strongly recommend you look at Mirror and Telepathy made by vis2k.  Granted, much of that work is Unity based, but moving it away to straight C# would be pretty straightforward.  Mirror means you're only writing your code once, and it's implemented for both the server and the client.  I've created a game using Mirror (which was realtime), and the performance was great, and since it's server authoritative, all of my standard hacking/cheating attempts failed.

If your game is turn based, I really don't understand the reasoning behind moving to UDP.  TCP would make your life much, much easier.

I checked out Mirror but since its just an implementation of Telepathy i switched to the async-await branch of telepathy. I will return with results if its any good or not.
https://github.com/vis2k/Telepathy/tree/async-await
Logged

pengu2
Level 0
**



View Profile WWW
« Reply #23 on: May 02, 2019, 09:47:11 AM »

For my game I'm using UDP, so I just have a dedicated thread that pulls data off of a single UDP socket and queues them up for other threads to consume. TCP is slightly more complicated since each connection will have a different socket, hence requiring something like `select`. C# definitely will have some kind of select function exposed. You will have to search for it, since I don't know C# very well.

Do you have a devlog or any screenshots of your game we can look at?
Logged

qMopey
Level 6
*


View Profile WWW
« Reply #24 on: May 05, 2019, 04:03:22 PM »

For my game I'm using UDP, so I just have a dedicated thread that pulls data off of a single UDP socket and queues them up for other threads to consume. TCP is slightly more complicated since each connection will have a different socket, hence requiring something like `select`. C# definitely will have some kind of select function exposed. You will have to search for it, since I don't know C# very well.

Do you have a devlog or any screenshots of your game we can look at?

Not yet Smiley
Logged
pengu2
Level 0
**



View Profile WWW
« Reply #25 on: May 06, 2019, 10:05:06 AM »

If this is your first foray into networking with client/server architecture and you're looking into using C#, I would strongly recommend you look at Mirror and Telepathy made by vis2k.  Granted, much of that work is Unity based, but moving it away to straight C# would be pretty straightforward.  Mirror means you're only writing your code once, and it's implemented for both the server and the client.  I've created a game using Mirror (which was realtime), and the performance was great, and since it's server authoritative, all of my standard hacking/cheating attempts failed.

If your game is turn based, I really don't understand the reasoning behind moving to UDP.  TCP would make your life much, much easier.

I checked out Mirror but since its just an implementation of Telepathy i switched to the async-await branch of telepathy. I will return with results if its any good or not.
https://github.com/vis2k/Telepathy/tree/async-await

After a few days of testing i gotta say i like the simplicity of telepathy, it seems to be very optimized and well tested.
I've been using https://github.com/neuecc/MessagePack-CSharp to serialize my messages and although you could halv the packet size by just constructing your own byte arrays with a packet identifier at the beginning of the array. Messagepack compensates for it by being easy to use and have minimal impact on CPU and Memory usage.
Logged

pengu2
Level 0
**



View Profile WWW
« Reply #26 on: May 06, 2019, 10:05:32 AM »

For my game I'm using UDP, so I just have a dedicated thread that pulls data off of a single UDP socket and queues them up for other threads to consume. TCP is slightly more complicated since each connection will have a different socket, hence requiring something like `select`. C# definitely will have some kind of select function exposed. You will have to search for it, since I don't know C# very well.

Do you have a devlog or any screenshots of your game we can look at?

Not yet Smiley

I'm gonna keep an eye out for it then Smiley
Logged

Pages: 1 [2]
Print
Jump to:  

Theme orange-lt created by panic