2017-07-17 19:42:36 +00:00
|
|
|
|
using System.Net;
|
2017-06-19 13:42:10 +00:00
|
|
|
|
using System.Net.Sockets;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Threading.Tasks;
|
2017-07-17 19:42:36 +00:00
|
|
|
|
using Newtonsoft.Json;
|
2017-06-19 13:42:10 +00:00
|
|
|
|
|
2017-07-17 19:42:36 +00:00
|
|
|
|
namespace NadekoBot.Common.ShardCom
|
2017-06-19 13:42:10 +00:00
|
|
|
|
{
|
|
|
|
|
public class ShardComClient
|
|
|
|
|
{
|
2017-06-25 04:09:23 +00:00
|
|
|
|
private int port;
|
|
|
|
|
|
|
|
|
|
public ShardComClient(int port)
|
|
|
|
|
{
|
|
|
|
|
this.port = port;
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-19 13:42:10 +00:00
|
|
|
|
public async Task Send(ShardComMessage data)
|
|
|
|
|
{
|
|
|
|
|
var msg = JsonConvert.SerializeObject(data);
|
|
|
|
|
using (var client = new UdpClient())
|
|
|
|
|
{
|
|
|
|
|
var bytes = Encoding.UTF8.GetBytes(msg);
|
2017-06-25 04:09:23 +00:00
|
|
|
|
await client.SendAsync(bytes, bytes.Length, IPAddress.Loopback.ToString(), port).ConfigureAwait(false);
|
2017-06-19 13:42:10 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|