public void Connect(string ip, int port) { client = new Telepathy.Client(); client.Connect(ip, port); Log($"Connecting to server at address {ip}, and port 9999", "Connecting"); }
// common public override void Shutdown() { Debug.Log("TelepathyTransport Shutdown()"); client?.Disconnect(); client = null; server?.Stop(); server = null; }
public static Telepathy.Client GetClient() { if (_client != null) { return(_client); } _client = new Telepathy.Client(); return(_client); }
public override void OnAwake() { base.OnAwake(); // create client & server client = new Telepathy.Client(clientMaxMessageSize); server = new Telepathy.Server(serverMaxMessageSize); // tell Telepathy to use Unity's Debug.Log Telepathy.Log.Info = Debug.Log; Telepathy.Log.Warning = Debug.LogWarning; Telepathy.Log.Error = Debug.LogError; // client hooks // other systems hook into transport events in OnCreate or // OnStartRunning in no particular order. the only way to avoid // race conditions where telepathy uses OnConnected before another // system's hook (e.g. statistics OnData) was added is to wrap // them all in a lambda and always call the latest hook. // (= lazy call) client.OnConnected = () => OnClientConnected.Invoke(); client.OnData = (segment) => OnClientDataReceived.Invoke(segment, Channels.DefaultReliable); client.OnDisconnected = () => OnClientDisconnected.Invoke(); // client configuration client.NoDelay = NoDelay; client.SendTimeout = SendTimeout; client.ReceiveTimeout = ReceiveTimeout; client.SendQueueLimit = clientSendQueueLimit; client.ReceiveQueueLimit = clientReceiveQueueLimit; // server hooks // other systems hook into transport events in OnCreate or // OnStartRunning in no particular order. the only way to avoid // race conditions where telepathy uses OnConnected before another // system's hook (e.g. statistics OnData) was added is to wrap // them all in a lambda and always call the latest hook. // (= lazy call) server.OnConnected = (connectionId) => OnServerConnected.Invoke(connectionId); server.OnData = (connectionId, segment) => OnServerDataReceived.Invoke(connectionId, segment, Channels.DefaultReliable); server.OnDisconnected = (connectionId) => OnServerDisconnected.Invoke(connectionId); // server configuration server.NoDelay = NoDelay; server.SendTimeout = SendTimeout; server.ReceiveTimeout = ReceiveTimeout; server.SendQueueLimit = serverSendQueueLimitPerConnection; server.ReceiveQueueLimit = serverReceiveQueueLimitPerConnection; // allocate enabled check only once enabledCheck = () => Enabled; Debug.Log("TelepathyTransport initialized!"); }
public void Setup() { client = new Telepathy.Client(); Log("Please enter the IP of the server below.", "Starting"); string ip = Console.ReadLine(); client.Connect(ip, 9999); Log($"Connecting to server at address {ip}, and port 9999", "Connecting"); Loop(); }
public override void Destroy() { if (client != null) { client.Disconnect(); client = null; } if (server != null) { server.Stop(); server = null; } }
bool IClientTransportLayer.Init(int channelId, OnConnected connectedCallback, Generic.Client.OnReceiveMessage messageCallback, OnDisconnected disconnectedCallback) { _client = new Telepathy.Client(); _channelId = channelId; _clientConnectedCallback = connectedCallback; _clientMessageCallback = messageCallback; _clientDisconnectedCallback = disconnectedCallback; SetupLogger(); return(true); }
public TelepathyTransport(bool isServer) : base(isServer) { Telepathy.Logger.Log = Debug.Log; Telepathy.Logger.LogWarning = Debug.LogWarning; Telepathy.Logger.LogError = Debug.LogError; if (isServer) { server = new Telepathy.Server(); } else { client = new Telepathy.Client(); } }
// client private void CreateClient() { // create client client = new Telepathy.Client(clientMaxMessageSize); // client hooks // other systems hook into transport events in OnCreate or // OnStartRunning in no particular order. the only way to avoid // race conditions where telepathy uses OnConnected before another // system's hook (e.g. statistics OnData) was added is to wrap // them all in a lambda and always call the latest hook. // (= lazy call) client.OnConnected = () => OnClientConnected.Invoke(); client.OnData = (segment) => OnClientDataReceived.Invoke(segment, Channels.Reliable); client.OnDisconnected = () => OnClientDisconnected.Invoke(); // client configuration client.NoDelay = NoDelay; client.SendTimeout = SendTimeout; client.ReceiveTimeout = ReceiveTimeout; client.SendQueueLimit = clientSendQueueLimit; client.ReceiveQueueLimit = clientReceiveQueueLimit; }
public override void ClientDisconnect() { client?.Disconnect(); client = null; }
public override void Awake() { TelepathyConfig conf = new TelepathyConfig(); if (!File.Exists("TelepathyConfig.json")) { File.WriteAllText("TelepathyConfig.json", JsonConvert.SerializeObject(conf, Formatting.Indented)); } else { conf = JsonConvert.DeserializeObject <TelepathyConfig>(File.ReadAllText("TelepathyConfig.json")); } NoDelay = conf.NoDelay; SendTimeout = conf.SendTimeout; ReceiveTimeout = conf.ReceiveTimeout; serverMaxMessageSize = conf.serverMaxMessageSize; serverMaxReceivesPerTick = conf.serverMaxReceivesPerTick; serverSendQueueLimitPerConnection = conf.serverSendQueueLimitPerConnection; serverReceiveQueueLimitPerConnection = conf.serverReceiveQueueLimitPerConnection; // create client & server client = new Telepathy.Client(clientMaxMessageSize); server = new Telepathy.Server(serverMaxMessageSize); // tell Telepathy to use Unity's Debug.Log Telepathy.Log.Info = Console.WriteLine; Telepathy.Log.Warning = Console.WriteLine; Telepathy.Log.Error = Console.WriteLine; // client hooks // other systems hook into transport events in OnCreate or // OnStartRunning in no particular order. the only way to avoid // race conditions where telepathy uses OnConnected before another // system's hook (e.g. statistics OnData) was added is to wrap // them all in a lambda and always call the latest hook. // (= lazy call) client.OnConnected = () => OnClientConnected.Invoke(); client.OnData = (segment) => OnClientDataReceived.Invoke(segment, 0); client.OnDisconnected = () => OnClientDisconnected.Invoke(); // client configuration client.NoDelay = NoDelay; client.SendTimeout = SendTimeout; client.ReceiveTimeout = ReceiveTimeout; client.SendQueueLimit = clientSendQueueLimit; client.ReceiveQueueLimit = clientReceiveQueueLimit; // server hooks // other systems hook into transport events in OnCreate or // OnStartRunning in no particular order. the only way to avoid // race conditions where telepathy uses OnConnected before another // system's hook (e.g. statistics OnData) was added is to wrap // them all in a lambda and always call the latest hook. // (= lazy call) server.OnConnected = (connectionId) => OnServerConnected.Invoke(connectionId); server.OnData = (connectionId, segment) => OnServerDataReceived.Invoke(connectionId, segment, 0); server.OnDisconnected = (connectionId) => OnServerDisconnected.Invoke(connectionId); // server configuration server.NoDelay = NoDelay; server.SendTimeout = SendTimeout; server.ReceiveTimeout = ReceiveTimeout; server.SendQueueLimit = serverSendQueueLimitPerConnection; server.ReceiveQueueLimit = serverReceiveQueueLimitPerConnection; // allocate enabled check only once enabledCheck = () => true; Console.WriteLine("TelepathyTransport initialized!"); }
public MmoClient() { _client = new Telepathy.Client(); LoopOtherThread = true; }