/// <summary> /// Launch the ClientNetwork /// </summary> /// <param name="channel">Name of the channel which will be used for the communication</param> /// <param name="callBackFct">Function called when the client receive a message from the server</param> /// <param name="serverIP">Ip of the server you want to connect to</param> /// <param name="serverPort">Port of the server you want to connect to</param> public void Start(string channel, Func <NetTools.Packet, int> callBackFct, string serverIP, int serverPort) { try { if (_serverIP == null) { _serverIP = serverIP; _serverPort = serverPort; CallBackFct = callBackFct; Channel = channel; NetworkComms.AppendGlobalIncomingPacketHandler <string>(Channel, ServerRequest); Connection.StartListening(ConnectionType.TCP, new System.Net.IPEndPoint(System.Net.IPAddress.Any, 0)); } } catch (Exception e) { Console.Error.WriteLine(e.Message); } }
/// <summary> /// Launch the ClientNetwork /// </summary> /// <param name="callBackFct">Function called when the client receive a message from the server</param> /// <param name="msgCallbackFct">Function called when the client received a chat message from the server</param> /// <param name="serverIP">Ip of the server you want to connect to</param> /// <param name="serverPort">Port of the server you want to connect to</param> public void Start(Func <Object, int> callBackFct, Func <string, int> msgCallbackFct, string serverIP, int serverPort) { try { if (_serverIP == null) { _serverIP = serverIP; _serverPort = serverPort; CallBackFct = callBackFct; MsgCallbackFct = msgCallbackFct; NetworkComms.AppendGlobalIncomingPacketHandler <string>("Message", ClientRequest); NetworkComms.AppendGlobalIncomingPacketHandler <string>("Chat", MsgRequest); Connection.StartListening(ConnectionType.TCP, new System.Net.IPEndPoint(System.Net.IPAddress.Any, 0)); } } catch (Exception e) { Console.Error.WriteLine(e.Message); } }