0
\$\begingroup\$

I have a client, and it's basically a potato client. What I mean by that is it's code is something like this: (This is a junky version of the code, just to make a point)

str input; str output; int inputnum; int outputnum;
cout << output;
if (output == 1) {
    cin << inputnum;
}
else {
    cin << input;
}

What I'm trying to do is send those input variables to and take those output variables from a server that does all the game logic and the like. The game is a text-based MUD.

I've seen a million things like this:

Complicated Graph. The elements are unimportant.

But I don't need that sort of thing. All I need is something like this:

[Client] ←→ [Server]

Because all the logic is on the server, so it's not important to do stuff like running it through accept sockets and the like. Is there a simple way to just connect four variables two going one way and two going the other? That's all I'm trying to do, but there aren't any simple ways to do that I've seen. Here's sort of an example of the sort of thing I'd like to happen:

Client 1:

Demon HP: [####################]
You used SWORD on DEMON!
Demon HP: [##################--]

Client 2:

Demon HP: [####################]
User1 used SWORD on DEMON!
Demon HP: [##################--]
\$\endgroup\$
4
  • 1
    \$\begingroup\$ Sorry, but you do need all that stuff. All that bind, listen and accept stuff is required to establish a connection between client and server over which you can then exchange data. \$\endgroup\$
    – Philipp
    Nov 9, 2022 at 0:34
  • 2
    \$\begingroup\$ Perhaps these help: TCP Server-Client implementation and UDP Server-Client implementation. Be aware, the network is fundamentally message based. You don't connect variables, you could instead send messages specifying which variable changes to which value. \$\endgroup\$
    – Theraot
    Nov 9, 2022 at 0:45
  • \$\begingroup\$ Why is it that I can't just include that logic on the server end? Some form of void bind/listen/accept {. . .} function that runs right away? \$\endgroup\$ Nov 9, 2022 at 0:46
  • 1
    \$\begingroup\$ What you're asking for doesn't exist in low level constructs. It's somewhat like asking for a simple way to make a variable keep its value across multiple runs of the program without having to open or close any files. It's unclear to me if you're asking for middleware that can do that for you (which is a shopping question and would be off topic), or if you're asking how to build netcode for an MUD (which is on topic, but very broad). My overall advice would to be follow the tutorials and abandon the idea that it "should" be simple. Computer networks are hard and have lots of sharp edge-cases. \$\endgroup\$
    – Tim C
    Nov 9, 2022 at 22:05

0

You must log in to answer this question.

Browse other questions tagged .