HI,
I want to have some clients and a server all running android. I want to connect all the clients to the server.
The clients will have a timer running on them, the servers job will be to show the status of what the clients are doing. I want to be able to send messages from the clients to the server about what it is doing. Is there a way to do this ?
Here is what i have so far but i am unable to catch the message on the server object.
Here is the clients code
using UnityEngine;
using System.Collections;
using UnityEngine;
using UnityEngine.Networking;
class RegisterHostMessage : MessageBase
{
public float message;
}
public class Client : MonoBehaviour {
NetworkClient myclient;
public UnityEngine.UI.Text conText;
public static short clientID = 123;
// Use this for initialization
void Start () {
SetUpclient ();
}
// Update is called once per frame
void SetUpclient () {
myclient = new NetworkClient ();
myclient.RegisterHandler (MsgType.Connect, OnConnected);
myclient.Connect ("10.244.144.201", 4444);
}
public void OnConnected(NetworkMessage netMsg)
{
RegisterHostMessage msg = new RegisterHostMessage ();
msg.message = 12.45f;
conText.text = "Connected to server";
myclient.Send (clientID,msg);
}
}
Here is the server’s code.
using UnityEngine;
using System.Collections;
using UnityEngine;
using UnityEngine.Networking;
public class Master : MonoBehaviour {
public UnityEngine.UI.Text masterip;
// Use this for initialization
void Start () {
SetUpServer ();
}
void SetUpServer()
{
NetworkServer.Listen (4444);
masterip.text = Network.player.ipAddress;
}
public void OnCommandSent(NetworkMessage netMsg)
{
Debug.Log (netMsg);
}
}
Any help will be good.