public void StartClient(string host, int port) { NetworkCommon = new NetworkClient(host, port); NetworkCommon.Receive(OnDataReceived); Invoke("ClientConnection", 0); }
public static void Interpret(IPEndPoint source, Message message, NetworkMessage network) { NetworkCommon networkCommon = GameObject.FindObjectOfType <Network> ().NetworkCommon; switch (network.Message) { case NetworkMessage.MessageValue.CONNECT: if (networkCommon is NetworkServer && networkCommon.ID == message.DestID) { (networkCommon as NetworkServer).Send(source, MessageTranslator.ToByteArray( createMessage(networkCommon.ID, message.SourceID, NetworkMessage.MessageValue.CONNECTED))); networkCommon.Connected = true; Application.LoadLevel(1); } break; case NetworkMessage.MessageValue.CONNECTED: if (networkCommon is NetworkClient && networkCommon.ID == message.DestID) { networkCommon.Connected = true; Application.LoadLevel(1); } break; } }
public static void Interpret(IPEndPoint source, Message message, GameplayMessage gameplay) { NetworkCommon networkCommon = GameObject.FindObjectOfType <Network> ().NetworkCommon; if (networkCommon == null) { return; } Player[] players = GameObject.FindObjectsOfType <Player>(); switch (gameplay.Message) { case GameplayMessage.MessageValue.MOVE: foreach (Player player in players) { if (player.ID == gameplay.PlayerID) { player.Move(gameplay.MoveDelta, gameplay.OldPosition, !(networkCommon is NetworkServer)); } } break; case GameplayMessage.MessageValue.ATTACK: foreach (Player player in players) { if (player.ID == gameplay.PlayerID) { player.Attack(); } } break; } }
public static void Send(GameplayMessage.MessageValue messageValue, int id, Vector2 delta, Vector3 originalPosition) { Network network = GameObject.FindObjectOfType <Network>(); if (network == null) { return; } NetworkCommon networkCommon = network.NetworkCommon; if (networkCommon == null) { return; } Message m = createMessage(networkCommon.ID, 1 - networkCommon.ID, messageValue, id, delta, originalPosition); if (networkCommon is NetworkClient) { (networkCommon as NetworkClient).Send(null, MessageTranslator.ToByteArray(m)); } else { (networkCommon as NetworkServer).Broadcast(MessageTranslator.ToByteArray(m)); } }
public void StartClient( string host, int port ) { NetworkCommon = new NetworkClient( host, port ); NetworkCommon.Receive( OnDataReceived ); Invoke("ClientConnection", 0); }
public void StartServer(int port) { NetworkCommon = new NetworkServer(port); NetworkCommon.Receive(OnDataReceived); }
public void StartServer( int port ) { NetworkCommon = new NetworkServer( port ); NetworkCommon.Receive( OnDataReceived ); }
private void Server_OnClientRegistered(NetworkCommon.Client client) { }