|
@@ -19,7 +19,7 @@ namespace Edge.Core.Processor.Communicator
|
|
[MetaPartsDescriptor(
|
|
[MetaPartsDescriptor(
|
|
"lang-zh-cn:Tcp(本程序为服务器端)通讯器lang-en-us:Tcp(as server) communicator",
|
|
"lang-zh-cn:Tcp(本程序为服务器端)通讯器lang-en-us:Tcp(as server) communicator",
|
|
"lang-zh-cn:基于TCP/IP技术的通讯器, FC作为服务器端等待客户端连接lang-en-us:TCP/IP based communicator, FC as the server and wait for connections")]
|
|
"lang-zh-cn:基于TCP/IP技术的通讯器, FC作为服务器端等待客户端连接lang-en-us:TCP/IP based communicator, FC as the server and wait for connections")]
|
|
- public class TcpServerCommunicator<T> : IClinet, ICommunicator<byte[], T> where T : MessageTemplateBase
|
|
|
|
|
|
+ public class TcpServerCommunicator<T> : ICommunicator<byte[], T> where T : MessageTemplateBase
|
|
{
|
|
{
|
|
private CancellationTokenSource readAsyncCancellationTokenSource;
|
|
private CancellationTokenSource readAsyncCancellationTokenSource;
|
|
private DateTime? lastReceiveMsgDataFromTcpClientDateTime;
|
|
private DateTime? lastReceiveMsgDataFromTcpClientDateTime;
|
|
@@ -32,7 +32,7 @@ namespace Edge.Core.Processor.Communicator
|
|
|
|
|
|
private int localTcpServerListeningPort;
|
|
private int localTcpServerListeningPort;
|
|
protected TcpListener tcpListener;
|
|
protected TcpListener tcpListener;
|
|
- public TcpClient exclusiveTcpClient { get; set; }
|
|
|
|
|
|
+ private TcpClient exclusiveTcpClient;
|
|
private string exclusiveTcpClient_ClientRemoteEndPoint_Str = "?:?";
|
|
private string exclusiveTcpClient_ClientRemoteEndPoint_Str = "?:?";
|
|
//private bool isTcpConnBrokenDuringWrite = false;
|
|
//private bool isTcpConnBrokenDuringWrite = false;
|
|
private object syncObject = new object();
|
|
private object syncObject = new object();
|
|
@@ -261,7 +261,7 @@ namespace Edge.Core.Processor.Communicator
|
|
{
|
|
{
|
|
lock (this.syncObject_Feed)
|
|
lock (this.syncObject_Feed)
|
|
{
|
|
{
|
|
- this.messageCutter.Feed(data);
|
|
|
|
|
|
+ this.messageCutter.Feed(data, this.localTcpServerListeningPort);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
catch (Exception ex)
|
|
@@ -298,8 +298,7 @@ namespace Edge.Core.Processor.Communicator
|
|
byte[] rawData;
|
|
byte[] rawData;
|
|
try
|
|
try
|
|
{
|
|
{
|
|
- rawData = message.ToCommonByteArray();
|
|
|
|
- //rawData = this.parser.Serialize(message);
|
|
|
|
|
|
+ rawData = this.parser.Serialize(message);
|
|
var arg = new CommunicatorEventArg<byte[], T>() { Data = rawData, Message = message, Continue = true };
|
|
var arg = new CommunicatorEventArg<byte[], T>() { Data = rawData, Message = message, Continue = true };
|
|
this.OnRawDataWriting?.Invoke(this, arg);
|
|
this.OnRawDataWriting?.Invoke(this, arg);
|
|
if (this.exclusiveTcpClient == null || !arg.Continue) { this.logger.LogError("Write failed, this.tcpClient is null: " + (this.exclusiveTcpClient is null)); return false; }
|
|
if (this.exclusiveTcpClient == null || !arg.Continue) { this.logger.LogError("Write failed, this.tcpClient is null: " + (this.exclusiveTcpClient is null)); return false; }
|
|
@@ -350,11 +349,5 @@ namespace Edge.Core.Processor.Communicator
|
|
{
|
|
{
|
|
throw new NotImplementedException();
|
|
throw new NotImplementedException();
|
|
}
|
|
}
|
|
-
|
|
|
|
-
|
|
|
|
- public TcpClient? GetTcpClient()
|
|
|
|
- {
|
|
|
|
- return this.exclusiveTcpClient;
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
}
|
|
}
|