# HG changeset patch # User riono # Date 1643096786 -32400 # Node ID dc3f59937772fa7769eefa510c0e30964a2489e5 # Parent b768fffe118c1212803a078cd075760fb5f7e044 remote dynamic diff -r b768fffe118c -r dc3f59937772 codegear/CodeGear.cs --- a/codegear/CodeGear.cs Tue Jan 18 21:16:37 2022 +0900 +++ b/codegear/CodeGear.cs Tue Jan 25 16:46:26 2022 +0900 @@ -45,7 +45,7 @@ idg.FinishInput(cgm, commandList); } - public void SetCommand(CommandType type, string toDgmName, string key, DataGear dg) { + public void SetCommand(CommandType type, string toDgmName, string key, DataGear dg) { Command command = new CommandBuilder().Init(type).Cg(this) .CgmID(cgm.cgmID) .ToDgmName(toDgmName) diff -r b768fffe118c -r dc3f59937772 daemon/AcceptThread.cs --- a/daemon/AcceptThread.cs Tue Jan 18 21:16:37 2022 +0900 +++ b/daemon/AcceptThread.cs Tue Jan 25 16:46:26 2022 +0900 @@ -16,36 +16,34 @@ } public void Run() { - while (true) { - try { - TcpClient client = null; - client = listener.AcceptTcpClient(); - client.NoDelay = true; + try { + TcpClient client = null; + client = listener.AcceptTcpClient(); + client.NoDelay = true; + + IPEndPoint endPoint = (IPEndPoint) client.Client.RemoteEndPoint; + IPAddress ipAddress = endPoint.Address; + IPHostEntry hostEntry = Dns.GetHostEntry(ipAddress); + Console.WriteLine("Accept " + hostEntry.HostName + ":" + endPoint.Port); + + Connection connection = new Connection(client.Client, cgm); + Console.WriteLine("connection:" + connection.GetInfoString()); + string key = "accept" + counter; - IPEndPoint endPoint = (IPEndPoint) client.Client.RemoteEndPoint; - IPAddress ipAddress = endPoint.Address; - IPHostEntry hostEntry = Dns.GetHostEntry(ipAddress); - Console.WriteLine("Accept " + hostEntry.HostName + ":" + endPoint.Port); - - Connection connection = new Connection(client.Client, cgm); - Console.WriteLine("connection:" + connection.GetInfoString()); - string key = "accept" + counter; - - IncomingTcpConnection incoming = new IncomingTcpConnection(connection); - Thread incomingThread = new Thread(incoming.Run); - incomingThread.Name = connection.GetInfoString() + "-IncomingTcp"; - incomingThread.Start(); - - cgm.SetAccept(key, incoming); - - OutboundTcpConnection outbound = new OutboundTcpConnection(connection); - Thread outboundThread = new Thread(outbound.Run); - outboundThread.Name = connection.GetInfoString() + "-OutboundTcp"; - outboundThread.Start(); - counter++; - } catch (Exception e) { - Console.WriteLine(e.StackTrace); - } + IncomingTcpConnection incoming = new IncomingTcpConnection(connection); + Thread incomingThread = new Thread(incoming.Run); + incomingThread.Name = connection.GetInfoString() + "-IncomingTcp"; + incomingThread.Start(); + + cgm.SetAccept(key, incoming); + + OutboundTcpConnection outbound = new OutboundTcpConnection(connection); + Thread outboundThread = new Thread(outbound.Run); + outboundThread.Name = connection.GetInfoString() + "-OutboundTcp"; + outboundThread.Start(); + counter++; + } catch (Exception e) { + Console.WriteLine(e.StackTrace); } } } diff -r b768fffe118c -r dc3f59937772 daemon/IncomingTcpConnection.cs --- a/daemon/IncomingTcpConnection.cs Tue Jan 18 21:16:37 2022 +0900 +++ b/daemon/IncomingTcpConnection.cs Tue Jan 25 16:46:26 2022 +0900 @@ -25,12 +25,10 @@ public void Run() { while (true) { - //TODO: Data長がわからないので1024で仮置き → ぴったしで読み込む必要がある // データはRemotemessage length, Remotemessage(Command), data length, dataの順で入っている - //byte[] packetSizeArray = new byte[4]; byte[] remoteMessageSizeArray = new byte[1]; byte[] remoteMessage; - byte[] dataSizeArray = new byte[4]; + byte[] dataSizeArray = new byte[1]; byte[] data; int dataLen; diff -r b768fffe118c -r dc3f59937772 datagear/command/PutCommand.cs --- a/datagear/command/PutCommand.cs Tue Jan 18 21:16:37 2022 +0900 +++ b/datagear/command/PutCommand.cs Tue Jan 25 16:46:26 2022 +0900 @@ -20,7 +20,7 @@ try { byte[] command = MessagePackSerializer.Serialize(CreateRemoteMessage()); byte[] commandsize = MessagePackSerializer.Serialize(command.Length); - byte[] data = new MessagePackDataGear(dg.GetData()).GetMessagePack(); + byte[] data = new MessagePackDataGear(dg.GetData()).GetMessagePack(); byte[] datasize = MessagePackSerializer.Serialize(data.Length); // Debug diff -r b768fffe118c -r dc3f59937772 datagear/dg/MessagePackDataGear.cs --- a/datagear/dg/MessagePackDataGear.cs Tue Jan 18 21:16:37 2022 +0900 +++ b/datagear/dg/MessagePackDataGear.cs Tue Jan 25 16:46:26 2022 +0900 @@ -59,14 +59,11 @@ // If deserialize data is not primitive type, it is dictionary public T MessagePackDataFormed(dynamic deserializedData) { var type = deserializedData.GetType(); - //Console.WriteLine(type); T instance; + if (type.IsPrimitive || type == typeof(string) || type == typeof(decimal)) { - //instance = Activator.CreateInstance(clazz, deserializedData); - // var typeInference = deserializedData; instance = Convert.ChangeType(deserializedData, clazz); } else { - //Dictionary dataDictionary = (Dictionary) deserializedData; List valueArray = new List(); foreach (var VARIABLE in (dynamic) deserializedData) { Console.WriteLine("val:" + VARIABLE);