How to allow chat between players

I am writing a game for the Android/IOS/Winphone platforms. I would like to socialize the game so that players can chat with each other if they happen to be playing the game at the same time. I already have written some code that will allow the player to enter chat text into a text box. I just don’t know how to send the text to another/random player who might be playing the game.

So in essence the code needs to be able to do the following:
Detect if another player is online. The other players identity will remain anonymous.
Be able to send chat text from one player to another.

Questions: How do I limit the chat pool to up to three players at a time?

I think games like Words with friends and dragon play poker allow for chatting between other players, I just need to know how chat can be implemented in my XNA game.

send the text to your server, then the server pushs the text to its connected clients.
its the only way to maintain anonymity.
if you dont care about anonymity then you can use peer2peer as well. (still requires a server or service that some1 else provides to store the address of whos online.)

those example games use a server too to make their games work at all.
simple mobile app servers are super cheap.

(you need to write the server programm yourself, something in php maybe is enough and very simple.)

1 Like

Thanks N_K, your input is deeply appreciated. Have a great day !

Hey N_K, any possible way you can send an http link or two? I googled and I think the type of server you talk about is sometimes referred to as a “lobby” server where players interact. I am not sure. Anyway, if you can point me to at least one link on the topic, that would help me a lot.

To add to @N_K s answer…
The thing where you connect two or more players with one another is often called ‘matchmaking’ and for that the ‘lobby’ is often used (server that distributes the messages among players and, finally, when the game is started, may connect them P2P doing a NAT-punchthrough)…
See https://github.com/UnterrainerInformatik/GameDevelopmentLinks#networking for some links.

First you’d need a network library (it’s steamworks.NET for me, but you could use lidgren as an independent alternative… I think @BlizzCrafter has done some work on a ‘write once, use on all major selling-platforms’ approach)
Then you’d need to implement a simple protocol, like [add] me to a lobby, [kick] someone from a lobby (steam opens a lobby if none exists for a specific key and deletes it if it has no members left; automatic lobby-leader-selection is nice as well; you’d like to start a game or kick someone, but you wouldn’t need that for a chat).
And: [send] a [message] to the server, [receive] a [message] from the server and [broadcast] a [message] to all but the sender…
Hope that helps.

edit: Oh… Feel free to add resources to the list on github I linked above as you find them. Sadly noone ever does that :slight_smile:

1 Like

If it’s just for chat, you could write a simple REST service and host it from your server.

I like writing a socket server to run on the server and have the clients connect to it.

I am planning ond doing something similar to this, and serving it from a cheap AWS server to start with. As it will be my socket server I will be able to write a library that can connet to it, I can then use it in any project, so MonoGame or Unity.

1 Like

I’m just gamedev hobbyist but I work in web client & server side development. But I think if you don’t want to manage your own servers maybe you could use Azure SignalR Service for this. Maybe with some Azure functions sprinkled in?

1 Like

I started a project for cross-platform networking (epic, steam, whatnot…) that should unify all those networking code under a more general API providing a vendor-independent implementation of the API as well so you could interchange those platforms before release and allow cross-play between those by using your own servers… Didn’t go over the planning-phase (have some tooling, server, etc… but far from done) and then Steam released steamworks as open-source.

To my knowledge someone now has already done exactly that. If not, the code I have so far is open-source and on github and open for collaboration, but it’s too much to pull off alone.

Server implementation wouldn’t be a problem (docker-based, linux, java-server, REST, MySql DB, Keycloak for user/password management, all running on a machine for like 10$ a month hosting costs for thousands of requests a minute … I already have a framework for that), but the ‘unified’ networking code providing enough convenience for the users is.

So if anyone has information about other approaches to that (cross-play, interchanging networking ‘libs’ for matchmaking, lobbies, achievements and leaderboards) please dm or reply since I’m interested in that kind of thing. And if there is no other approach/implementation, then why don’t we make one?

edit: Here is the link. But it’s currently a mess; I warned you :slight_smile: https://github.com/UnterrainerInformatik/Nexus

2nd edit: I just tried to find the posting that mentioned that ready-to-use cross-platform lib… and it seems that I didn’t remember correctly. So to my knowledge there is no such lib. For steam there is https://github.com/Facepunch/Facepunch.Steamworks that seems like the place to go if you went for steam.

For chat, I think it naturally would mean real-time 2-way communication. For that, SignalR or socketIO on node are good starting points. It’ll allow you to focus on the logic of data (like rooms, users chats, etc.) and focus less on the details underneath.
From a cost-saving perspective, however, these techniques require websockets. All the big players are going to limit the amount of connections you have going, so this isn’t going to scale for free. Azure has something called a SignalR Service to assist with this that might be worth looking into.

If you are ok with near-real-time instead, you could always build a WebAPI and simply doing polling against it. Store a queue of messages behind it with a job that deletes messages after a certain point. A little hacky but it could also get the job done.

1 Like