Sending a string of text from server to client and vice versa

So I’m working on a mostly text based game, and its almost done… well if not being able to play it in network can be counted as almost than yeah…

I just need to send text from text box on a server to a label on a client, and vice versa. I’ve been trying to find something relevant to my problem but nothing came up.

Here’s my code:

using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class NetTesting : MonoBehaviour {

    public string connectionIP = "127.0.0.1";
    public int connectionPort = 25001;

    public Text status;

    public void ClientConnect()
    {
        Network.Connect("127.0.0.1", 25001);
    }

    public void Host()
    {
        Network.InitializeServer(32, connectionPort, false);
    }

    void Update()
    {
        if (Network.isServer)
        {
            status.text = "You are the host";
        }
        if (Network.peerType == NetworkPeerType.Client)
        {
            status.text = "You are the client";
        }
        if (Network.peerType == NetworkPeerType.Disconnected)
        {
            status.text = "Disconnected";
        }
    }

}

I won’t even bother posting all the things I’ve tried to make it work.

Thank you people!

I’m sure I’m the wrong person to be answering questions, but I don’t see any attempt in this code to send text anywhere, or even a reason to send text anywhere.

For a text based game, I’m sure you’ll probably want to use the high level API for networking.

I’ve removed the code I’ve been trying to use, cause none of it seemed to work. I didn’t manage to make something that even remotely makes sense. I was hoping someone can give me an example.

If it’s really just about sending strings, I’d just use standard C# sockets as they are very easy to use if you have some experience with them.

Thats the second plan, but the problem is that both server and client have to be synced. Is there any simple messaging example or something like that? I found a chat system, but its way to complicated for me to understand how network works.

To be honest, if you struggle on simple chat networking you should take some time - Look up for Async socket & TCP/UDP protocols.

Or stick with unitys default networking libary.