L
L
lpinvie2018-12-10 21:39:03
Computer networks
lpinvie, 2018-12-10 21:39:03

Game snake C# (Windows Forms), which technology to choose for the interaction of players over the network?

Hello everyone, I decided to write a snake in C # (Windows Forms). I want to add a network mode to the game, i.e. so that 2 players connect to the server and play together. Those. there will be 2 snakes on the map. I know only Sockets, but knowledge at the level of "transmit a message". I heard that there is WCF, but I have no idea what is there and how. So, with the help of what technology is it best to implement network interaction? The server itself will be on Ubuntu Server 16.04 OS.

Answer the question

In order to leave comments, you need to log in

3 answer(s)
E
eRKa, 2018-12-11
@lpinvie

Here I would not recommend tcp. In general, in most multiplayer games, tcp is contraindicated, you will receive delays, friezes. You will have one field for two and get a desynchronization that the enemy will eat the apple that you have already eaten.
You use the upd protocol, according to it regularly, once in a certain period of time, you receive the coordinates of the entire list of snakes from the enemy and the direction of movement, and you yourself, to him, broadcast your own. On your screen, the enemy's snake has no logic, only a display: you have displayed all the received coordinates and move it in the received direction until you receive new data.
Once, as a coursework, I took Tetris over the network, only on wpf. The implementation was exactly as described. The game was only in LAN, between computers, without any central servers.

R
rPman, 2018-12-11
@rPman

Connection is ordinary tcp sockets (do not climb into udp yet, but it’s also possible with them).
Transfer only the pressed buttons of users to the server, literally, byte by byte (assign codes for all possible actions of users, thoroughly, depending on your gameplay, it can even be pressed the button - released the button).
From the server, you transfer changes to the screen content, by objects, snakes, food, and so on. Of course, when connecting, instead of delta, the server should return the current coordinates. If the connection is lost, then everything will be automatically restored. Develop a message format, use ready-made serializers, don't invent a locomotive, though...
On the client, you redraw all this every time you receive data from the server.
The whole game should be spinning on the server, then you will not have any problems with out of sync, cheating (except for automation) and other things.
The disadvantage is that all users will have a small lag in their actions, depending on the pings.
Unfortunately, not all games can be implemented this way, but partially yes.

G
Griboks, 2018-12-10
@Griboks

1) Develop a network communication protocol.
2) Select the language for writing the server.
3) Oh miracle! It's C#! Run on msdn and read the example about online chat.
4) Remove all lines and other nonsense from the network code.
5) You have bad protocol. Improve it, patch holes, protect yourself from cheating.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question