public void HandlePacket(NetTcpServer server, NetTcpClient client, object packet) { switch (packet) { case PlayerShotPacket playerShotPacket: PacketHandlers.ProcessPacket(CreatePacketContext(playerShotPacket, client)); break; case PlayerSpawnAtPacket playerSpawnAtPacket: PacketHandlers.ProcessPacket(CreatePacketContext(playerSpawnAtPacket, client)); break; case PlayerTeamJoinPacket playerTeamJoinPacket: PacketHandlers.ProcessPacket(CreatePacketContext(playerTeamJoinPacket, client)); break; case PlayerJumpPacket playerJumpPacket: PacketHandlers.ProcessPacket(CreatePacketContext(playerJumpPacket, client)); break; case PlayerFlowPacket playerFlowPacket: PacketHandlers.ProcessPacket(CreatePacketContext(playerFlowPacket, client)); break; } }
public BeepClient() { IConfiguration config = new ConfigurationBuilder() .AddJsonFile("clientSettings.json", false, true) .Build(); using var loggerFactory = LoggerFactory.Create(x => x .AddConfiguration(config.GetSection("Logging")) .AddConsole()); Logger = loggerFactory.CreateLogger <BeepClient>(); IConfigurationSection networkConfig = config.GetSection("Network"); IPAddress hostAddress = IPAddress.Parse(networkConfig.GetValue <string>("Address")); int port = networkConfig.GetValue <int>("TcpPort"); //TcpClient tcpClient = new TcpClient(new IPEndPoint(hostAddress, port)); TcpClient tcpClient = new TcpClient(networkConfig.GetValue <string>("Address"), port); NetTcpClient client = new NetTcpClient(tcpClient, new StreamProtobuf(PrefixStyle.Base128, Packet.PacketTypes)); client.PacketReceivedEvent += HandlePacket; BeepLiveSfml = new BeepLiveSfml(new MessageSender(client)); _ = client.AcceptPackets(); BeepLiveSfml.Run(); }
public PacketContext(TPacket packet, BeepServer server, NetTcpClient sender, ILogger logger) { Packet = packet; Server = server; Sender = sender; Logger = logger; }
/// <summary> /// On Send data /// </summary> /// <param name="sender"></param> /// <param name="data"></param> void tcpClient_onSendData(NetTcpClient sender, Common.Model.CommandResult data) { if (null != onSendData) { onSendData(sender, data); } }
private void Client_onReceiveData(NetTcpClient sender, CommandResult data) { Invoke((Action) delegate { listBox1.Items.Insert(0, "C - Receive data" + data.message); }); }
private void Server_onAcceptClient(NetTcpServer sender, NetTcpClient client) { Invoke((Action) delegate { listBox1.Items.Insert(0, "Connected"); }); }
void tcpClient_onError(NetTcpClient sender, Common.Model.CommandResult data) { Invoke((Action) delegate { listBox1.Items.Insert(0, sender.host + "- > Error : " + data.message); }); }
void tcpClient_onConnect(NetTcpClient sender) { Invoke((Action) delegate { listBox1.Items.Insert(0, sender.host + "- > Connect"); }); }
void tcpClient_onReceiveData(NetTcpClient sender, Common.Model.CommandResult data) { Invoke((Action) delegate { listBox1.Items.Insert(0, sender.host + "- > Recieve data " + Encoding.UTF8.GetString(data.model as byte[])); }); }
/// <summary> /// OnError /// </summary> /// <param name="sender"></param> /// <param name="data"></param> void tcpClient_onError(NetTcpClient sender, Common.Model.CommandResult data) { if (null != onError) { onError(sender, data); connectCount++; if (null != writeThread) { writeThread.Abort(); } } ///TODO : PARSE ERROR if (data.id == 999) { if (connectCount < 4) { tryToConnect(); if (msr.WaitOne()) { connect(); } } } }
/// <summary> /// On Connect /// </summary> /// <param name="sender"></param> void tcpClient_onConnect(NetTcpClient sender) { if (null != onConnect) { onConnect(sender); } }
private void Server_onReceiveData(NetTcpServer sender, NetTcpClient client, CommandResult data) { Invoke((Action) delegate { listBox1.Items.Insert(0, "S - Receive data" + data.message); }); client.write("Response "); }
/// <summary> /// OnDisConnect /// </summary> /// <param name="sender"></param> void tcpClient_onDisconnect(NetTcpClient sender) { if (null != onDisconnect) { writeThread.Abort(); onDisconnect(sender); } }
/// <summary> /// On Connect /// </summary> /// <param name="sender"></param> void tcpClient_onConnect(NetTcpClient sender) { if (null != onConnect) { onConnect(sender); } tryToWriteData(); connectCount = 0; }
void t_onReceiveData(NetTcpClient sender, Common.Model.CommandResult data) { string s = Encoding.UTF8.GetString(data.model as byte[]); Invoke((Action) delegate { listBox1.Items.Insert(0, s); }); }
/* * Commands (CLIENT): * GET_LAST_TAG * * Commands (SERVER): * NEW_TAG */ #region Methods /// <summary> /// Parse Command /// </summary> /// <param name="client"></param> /// <param name="data"></param> public static void parseCmd(NetTcpClient client, CommandResult data) { if ((null != client) && (null != data) && !data.message.isNullOrEmptyOrWhiteSpaceOrLen()) { string cmd = data.message.ToLower(); if (cmd == "get_last_tag") { // Get last tag } } }
private void button4_Click(object sender, EventArgs e) { server = new NetTcpServer(10000, 1024); client = new NetTcpClient("127.0.0.1", 10000, 1024); server.start(); client.connect(); client.onReceiveData += Client_onReceiveData; server.onReceiveData += Server_onReceiveData; server.onAcceptClient += Server_onAcceptClient; }
public AntennaClient(string host, int port, int bufferSize) { msr = new ManualResetEvent(false); connectorInterval = new TimeSpan(0, 0, 15); tcpClient = new NetTcpClient(host, port, bufferSize); tcpClient.onConnect += tcpClient_onConnect; tcpClient.onDisconnect += tcpClient_onDisconnect; tcpClient.onError += tcpClient_onError; tcpClient.onReceiveData += tcpClient_onReceiveData; tcpClient.onSendData += tcpClient_onSendData; }
public void HandlePacket(NetTcpClient client, object packet) { switch (packet) { case PlayerJumpPacket _: case PlayerShotPacket _: case PlayerSpawnAtPacket _: case PlayerTeamJoinPacket _: case ServerFlowPacket _: case SyncPacket _: BeepLiveSfml.HandlePacket((Packet)packet); break; } }
/// <summary> /// OnError /// </summary> /// <param name="sender"></param> /// <param name="data"></param> void tcpClient_onError(NetTcpClient sender, CommandResult data) { if (null != onError) { onError(sender, data); connectCount++; } ///TODO : PARSE ERROR if (data.id == 999) { if (connectCount < 10) { tryToConnect(); if (msr.WaitOne()) { connect(); } } } }
private PacketContext <TPacket> CreatePacketContext <TPacket>(TPacket packet, NetTcpClient sender) where TPacket : Packet => new PacketContext <TPacket>(packet, this, sender, Logger);
public MessageSender(NetTcpClient client) { _client = client; }
/// <summary> /// TcpServer /// </summary> /// <param name="sender"></param> /// <param name="client"></param> /// <param name="data"></param> private void TcpServer_onReceiveData(NetTcpServer sender, NetTcpClient client, CommandResult data) { Helper.ClientMethodParser.parseCmd(client, data); }