Add Ping command
This commit is contained in:
@@ -1,4 +1,8 @@
|
||||
using System;
|
||||
using PlantBox.Shared.Communication;
|
||||
using PlantBox.Shared.Communication.Commands;
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Net.Sockets;
|
||||
|
||||
namespace PlantBox.Broker
|
||||
{
|
||||
@@ -7,6 +11,29 @@ namespace PlantBox.Broker
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine("Hello World!");
|
||||
var listener = new TcpListener(IPAddress.Any, Connection.TCP_PORT);
|
||||
listener.Start();
|
||||
|
||||
while (true)
|
||||
{
|
||||
try
|
||||
{
|
||||
var client = listener.AcceptTcpClient();
|
||||
var stream = new CommandStream(client.GetStream());
|
||||
|
||||
var command = stream.Receive();
|
||||
Console.WriteLine(command);
|
||||
|
||||
var ping = new Ping().Deserialize(command.Arguments);
|
||||
Console.WriteLine($"Ping: {ping.Message}");
|
||||
|
||||
stream.Send(new Ping(ping.Message).ToCommandPacket(Command.Ping, command.ID));
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user