Telepathy
Telepathy copied to clipboard
Server disconnects client after ~3 seconds.
The title says it all. Here is the server and client code.
Server code:
using System;
using System.Text;
using Telepathy;
namespace TelepathyTestServer {
class Program {
static void Main(string[] args) {
const int MaxMessageSize = 8 * 1024;
Encoding utf8 = Encoding.UTF8;
Server server = new Server(MaxMessageSize);
server.OnConnected = (connectionId) => {
Console.WriteLine("Client [{0}] connected.", connectionId);
byte[] msg = utf8.GetBytes("Hello from server.");
server.Send(connectionId, new ArraySegment<byte>(msg));
};
server.OnData = (connectionId, data) => {
Console.WriteLine(connectionId + " Data: " + utf8.GetString(data.Array, 0, data.Count));
};
server.OnDisconnected = (connectionId) => Console.WriteLine("Client [{0}] disconnected.", connectionId);
server.Start(5200);
while (true) {
server.Tick(100);
System.Threading.Thread.Sleep(1);
}
}
}
}
Client code:
using System;
using System.Text;
using Telepathy;
namespace ClientTest {
class Program {
static void Main(string[] args) {
const int MaxMessageSize = 8 * 1024;
Encoding utf8 = Encoding.UTF8;
Client client = new Client(MaxMessageSize);
client.OnConnected = () => {
Console.WriteLine("Connected to server.");
byte[] msg = utf8.GetBytes("Hello from client.");
client.Send(new ArraySegment<byte>(msg));
};
client.OnData = (data) => Console.WriteLine(utf8.GetString(data.Array, 0, data.Count));
client.OnDisconnected = () => Console.WriteLine("Disconnected from server.");
client.Connect("127.0.0.1", 5200);
System.Threading.Thread.Sleep(100);
while (true) {
client.Tick(100);
System.Threading.Thread.Sleep(1);
}
}
}
}```
Hi,
This is due to ReceiveTimeout in Common.cs -> set it to 0 or use a periodic heartbeat system.
Ok thanks. Great feature BTW!