The title says it all, i was just wondering if i made a simple text based game what would i use? Like I've heard about things called sockets, ports etc? Just in curiosity

Dani AI

Generated

For a simple two‑player text game in C++, there are two easy paths: both players on one machine (threads or simple IPC) or players over a network (small server + clients). pointed to a good introductory socket guide, and correctly described the client/server split — build a tiny host program that keeps the authoritative state and lightweight clients that send commands.

Practical checklist to get started:

  • Pick a networking layer: raw BSD sockets / Winsock if you want to learn the details, or a higher‑level library like Boost.Asio (cross‑platform) or SFML (beginner friendly) to avoid boilerplate.
  • Design a simple, line‑based protocol (ASCII commands terminated by newline). That avoids framing headaches for a text game.
  • Implement server: accept connections, spawn a reader (thread or async handler) per client, validate each command, update game state, and send state or confirmations back.
  • Implement client: connect, run a reader thread for incoming messages, and a main loop for user input and sending commands.
  • Start testing on localhost (127.0.0.1) with two terminal windows before trying across the internet.

Common gotchas and tips:

  • Use TCP for reliability in text games; UDP forces you to handle packet loss and ordering.
  • Beware blocking reads — use nonblocking/async IO or threads.
  • For internet testing, check firewalls and port forwarding.
  • Log messages and test with tools like telnet/netcat to debug the server protocol.
  • Validate and bound input lengths to avoid crashes if you expose the server.

This approach keeps scope small, teaches the fundamentals, and gets a playable two‑player prototype quickly.

Recommended Answers

All 2 Replies

For a client server model, you will have to code seperately for the server and seperately for the client. The server will basically keep track of all the data like scores, players etc. And the clients would basically be the different players.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.