Skip to content
Sign upLog in
← Back to Community
Websockets, or webservers?
Profile icon
hacker
has Hacker Plan
Dart

If I wanted to make a game in python that’s text bassed, and I wanted to be able to play with someone else, would it be better to use a web server or websocket to communicate data?

Answered by Baconman321 [earned 5 cycles]
View Answer
Voters
Profile icon
figglediggle
Profile icon
Dart
Comments
hotnewtop
Profile icon
Baconman321

Websockets are quite worth it. That said, it really depends. If your game periodically sends data, you could always go for long polling (AJAX requests periodically).

Web sockets allow connections between the server and the client without having to send additional headers each time a message is sent.

Websockets are most of the time used for games, so yes I would definitely recommend websockets.

Profile icon
Dart

@Baconman321
very helpful, thank you :)

Profile icon
Baconman321

@Dart
If it's in the terminal, then you can use network sockets instead. They support UDP, which sends info rapidly without guarantee of the info being received and in order. It sounds bad, but for fast-paced games it is perfect.

Profile icon
Dart

@Baconman321
im planning on making a clone of uno actually so it doesnt have to be lightning fast

Profile icon
Baconman321

@Dart
TCP will work fine for you then.

Profile icon
SLMJ

@Baconman321
I'm making a little r/place clone in javascript using websockets, but I am getting ~100 to ~200 ms latency, It's really annoying. Is there anything I can do to improve the speed? (I'm sending little json messages, eg. {x: 35, y: 205, color: [255, 123, 43]})

Profile icon
Baconman321

@SLMJ
It really depends on what is going on. It will be extremely hard just externally what is going on.

I know I am making a little program (website) that has to send messages across worker threads and the latency is up to 1 second! However, that isn't with the websockets, rather, it is with the main thread getting so occupied that it can't maintain a steady and quick cycle (using requestAnimationFrame). From what I can guess, it would probably either be the network or the program itself that is causing the latency.