diff --git a/App.config b/App.config
index 1bcae48..b9492c7 100644
--- a/App.config
+++ b/App.config
@@ -3,7 +3,8 @@
-
-
+
+
+
\ No newline at end of file
diff --git a/Hander/MultiUserHandle.cs b/Hander/MultiUserHandle.cs
index 60a84e1..1f17688 100644
--- a/Hander/MultiUserHandle.cs
+++ b/Hander/MultiUserHandle.cs
@@ -12,11 +12,12 @@ namespace OnlineUserPool.Hander
{
public class MultiUserHandle : IHandle
{
- private int _index = -1;
+ private int _index = 0; //3600*3;
private MultiUserModel model;
private TurfHelper _turfHelper;
- private int _routeId = 4297; //1660;
- private int _size = 200;
+ private int _routeId = 1255; //5593; //1660;
+ private int _size = 50;
+ private int _competitionid = 0;//35;
public MultiUserHandle()
{
Init();
@@ -24,11 +25,23 @@ namespace OnlineUserPool.Hander
public async void Init()
{
+ #region 环台湾
+ //_routeId = 5593;
+ //_competitionid = 35;
+ //_index = 3600 * 3;
+ #endregion
+
+
+ #region sis
+ //_routeId = 5710;
+ //_competitionid = 37;
+ #endregion
+
model = await BaseApi.GetAsync($"/Map/sss?routeId={ _routeId }&size={ _size }");
double i = 0;
foreach (var item in model.users)
{
- i += 0.0005;
+ i += 0.0002;
item.Distance = i;
}
_turfHelper = new TurfHelper(model.route.List.Select(d => d.Point));
@@ -68,7 +81,7 @@ namespace OnlineUserPool.Hander
Speed = item.Speed,
WeightKg = 0,
PreDistance = preDistance,
- Competitionid = 30
+ Competitionid = _competitionid
};
msgModels.Add(info);
}
diff --git a/Services/TcpService1.cs b/Services/TcpService1.cs
index ee79564..3ec0e53 100644
--- a/Services/TcpService1.cs
+++ b/Services/TcpService1.cs
@@ -1,5 +1,6 @@
using NetCoreServer;
using OnlineUserPool.Model;
+using OnlineUserPool.Unility;
using Serilog;
using System;
using System.Collections.Generic;
@@ -24,7 +25,7 @@ namespace OnlineUserPool.Services
{
//throw new NotImplementedException();
//_action = action;
- _server = new PfTcpServer(IPAddress.Any, 11001, (ip, model)=> {
+ _server = new PfTcpServer(IPAddress.Any, ConfigHelp.TcpPort, (ip, model)=> {
action(ip, model, this);
});
//_server.OptionNoDelay = true;
@@ -40,6 +41,7 @@ namespace OnlineUserPool.Services
return;
}
_server.Multicast(dgram);
+
}
class PfTcpServer : TcpServer
@@ -81,26 +83,44 @@ namespace OnlineUserPool.Services
//base.OnDisconnected();
Debug.WriteLine("Tcp断开连接");
}
-
+ private string temp = "";
protected override void OnReceived(byte[] buffer, long offset, long size)
{
//base.OnReceived(buffer, offset, size);
- var returnData = Encoding.UTF8.GetString(buffer, (int)offset, (int)size);
+
//Debug.WriteLine(returnData);
//Log.Information(returnData + "\r\n");
+ string returnData = "";
try
{
+ returnData = Encoding.UTF8.GetString(buffer, (int)offset, (int)size);
//var msg = Newtonsoft.Json.JsonConvert.DeserializeObject(returnData);
//var ipEndPoint = IPEndPoint.Parse(this.Socket.RemoteEndPoint.ToString());
//_action(ipEndPoint, msg);
-
- foreach (var item in returnData.Split(new string[] { "}" }, StringSplitOptions.RemoveEmptyEntries))
+ foreach (var item in returnData)
{
- //if (string.IsNullOrWhiteSpace(item)) continue;
- var msg = Newtonsoft.Json.JsonConvert.DeserializeObject(item + "}");
- var ipEndPoint = IPEndPoint.Parse(this.Socket.RemoteEndPoint.ToString());
- _action(ipEndPoint, msg);
+ if(item == '}')
+ {
+ temp += item;
+ var msg = Newtonsoft.Json.JsonConvert.DeserializeObject(temp);
+ var ipEndPoint = IPEndPoint.Parse(this.Socket.RemoteEndPoint.ToString());
+ _action(ipEndPoint, msg);
+
+ temp = "";
+ }
+ else
+ {
+ temp += item;
+ }
}
+
+ //foreach (var item in returnData.Split(new string[] { "}" }, StringSplitOptions.RemoveEmptyEntries))
+ //{
+ // //if (string.IsNullOrWhiteSpace(item)) continue;
+ // var msg = Newtonsoft.Json.JsonConvert.DeserializeObject(item + "}");
+ // var ipEndPoint = IPEndPoint.Parse(this.Socket.RemoteEndPoint.ToString());
+ // _action(ipEndPoint, msg);
+ //}
}
catch (Exception ex)
{
diff --git a/Services/UdpService.cs b/Services/UdpService.cs
index dccba6e..55eb033 100644
--- a/Services/UdpService.cs
+++ b/Services/UdpService.cs
@@ -23,7 +23,7 @@ namespace OnlineUserPool.Services
public void RunServer(Action action)
{
- udpServer = new UdpClient(ConfigHelp.Port);
+ udpServer = new UdpClient(ConfigHelp.UdpPort);
uint IOC_IN = 0x80000000;
uint IOC_VENDOR = 0x18000000;
uint SIO_UDP_CONNRESET = IOC_IN | IOC_VENDOR | 12;
diff --git a/Unility/ConfigHelp.cs b/Unility/ConfigHelp.cs
index a6010c7..f8aa254 100644
--- a/Unility/ConfigHelp.cs
+++ b/Unility/ConfigHelp.cs
@@ -18,7 +18,9 @@ namespace OnlineUserPool.Unility
//public static string Ip { get; private set; }
- public static int Port { get; private set; }
+ public static int UdpPort { get; private set; }
+
+ public static int TcpPort { get; private set; }
static ConfigHelp()
@@ -27,7 +29,10 @@ namespace OnlineUserPool.Unility
//Top = Convert.ToInt32(System.Configuration.ConfigurationManager.AppSettings["Top"]);
ShowVirtualUser = bool.Parse(System.Configuration.ConfigurationManager.AppSettings["ShowVirtualUser"]);
//Ip = System.Configuration.ConfigurationManager.AppSettings["Ip"];
- Port = int.Parse(System.Configuration.ConfigurationManager.AppSettings["Port"]);
+ UdpPort = int.Parse(System.Configuration.ConfigurationManager.AppSettings["Port"]);
+
+ TcpPort = int.Parse(System.Configuration.ConfigurationManager.AppSettings["TcpPort"]);
+
}
}
}
diff --git a/ViewModels/MainWindowViewModel.cs b/ViewModels/MainWindowViewModel.cs
index 9468500..3ba82fb 100644
--- a/ViewModels/MainWindowViewModel.cs
+++ b/ViewModels/MainWindowViewModel.cs
@@ -54,15 +54,16 @@ namespace OnlineUserPool.ViewModels
//private IService _udpService;
public MainWindowViewModel()
{
- Title = $"{ IPAddress.Any }:{ ConfigHelp.Port }";
+ Title = $"{ IPAddress.Any }:{ ConfigHelp.UdpPort }";
dispatcher = Dispatcher.CurrentDispatcher;
//Customers.Add("suntao");
WriteLine(DateTime.Now.ToShortDateString());
LogHelper.Init();
- mapRecordRankingHander = new MapRecordRankingHander();
- Log.Information($"初始化连接,当前地址:{ IPAddress.Any }:{ConfigHelp.Port}");
+ mapRecordRankingHander = new MultiUserHandle();//new MapRecordRankingHander();
+ //mapRecordRankingHander = new MultiUserHandle();
+ Log.Information($"初始化连接,当前地址:{ IPAddress.Any }:{ConfigHelp.UdpPort}");
new TcpService1().RunServer(ReceivedData);
//var tet = new System.Collections.Concurrent.ConcurrentBag