public void Execute(Message msg, EasyTcpClient client) { Packet pack = msg.GetPacket; Console.WriteLine($"Some packet executed. | {BitConverter.ToInt32(pack.RawData, 0)}"); msg.Reply(new Packet(BytesTransformation.TransformIt(r.Next(1, 9999)), "Some packet")); }
static void Main(string[] args) { EasyTcpClient client = new EasyTcpClient(System.Reflection.Assembly.GetExecutingAssembly()); client.OnConnected += (sender, tcp) => { Console.WriteLine("Client successfuly connected!"); client.Send(new Packet(BytesTransformation.TransformIt("Test String", "Test String2", 1337, true, 412.214, 4124u), "Some packet")); }; client.OnDisconnect += (sender, tcp) => { Console.WriteLine("Client disconnected!"); }; client.OnError += (sender, error) => { Console.WriteLine($"{error.Message}\n{error.StackTrace}"); }; client.DataReceived += (sender, msg) => { Console.WriteLine($"PacketType: {msg.GetPacket.PacketType}"); client.PacketHandler(msg, false); }; if (!client.Connect("127.0.0.1", 6124, TimeSpan.FromSeconds(15))) { Console.WriteLine("Connection aborted. Timeout!"); } Console.ReadLine(); Task.Delay(-1).Wait(); }
public void Execute(Message msg, EasyTcpServer server) { Packet pack = msg.GetPacket; List <object> f = BytesTransformation.TransformToObject(pack.RawData, typeof(string), typeof(string), typeof(int), typeof(bool), typeof(double), typeof(uint)); string readed = (string)f[0]; string readed2 = (string)f[1]; int readed3 = (int)f[2]; bool readed4 = (bool)f[3]; double readed5 = (double)f[4]; Console.WriteLine($"{f[5].GetType()}"); Int64 readed6 = (Int64)f[5]; Console.WriteLine($"Some packet executed. | {readed} | {readed2} | {readed3} | {readed4} | {readed5} | {readed6}"); msg.Reply(new Packet(BytesTransformation.TransformIt("AnyData.txt", BytesCompress.Compress(File.ReadAllBytes("AnyData.txt"))), "Data")); //msg.Reply(new Packet(BitConverter.GetBytes(r.Next(1, 9999)), "Some packet")); }
public void CommandListener() { while (true) { if (LockReadLine) { continue; } Console.Write("> "); string cmd = Console.ReadLine(); if (!string.IsNullOrEmpty(cmd)) { Handler.Client.Send(BytesCompress.CompressPacket(BytesTransformation.TransformIt(cmd), "CPacket")); LockReadLine = true; } Thread.Sleep(50); } }
public void SendMessage(OClient msgType, string msg, Socket client) => Handler.Server.Send(client, BytesCompress.CompressPacket(BytesTransformation.TransformIt((int)msgType, msg), "OPacket"));