增加模拟用户功能

This commit is contained in:
suntao committed 2021-06-24 09:20:01 +08:00
1 parent 0e931a3ac9
commit b9bb485a2d
7 files changed
+107 -28

No files matched your search

+29 -9
View File
@@ -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<MsgModel>(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<MsgModel>(item + "}");
var ipEndPoint = IPEndPoint.Parse(this.Socket.RemoteEndPoint.ToString());
_action(ipEndPoint, msg);
if(item == '}')
{
temp += item;
var msg = Newtonsoft.Json.JsonConvert.DeserializeObject<MsgModel>(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<MsgModel>(item + "}");
// var ipEndPoint = IPEndPoint.Parse(this.Socket.RemoteEndPoint.ToString());
// _action(ipEndPoint, msg);
//}
}
catch (Exception ex)
{
+1 -1
View File
@@ -23,7 +23,7 @@ namespace OnlineUserPool.Services
public void RunServer(Action<IPEndPoint, MsgModel, IService> 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;