Mercurial > hg > Database > Christie-sharp
changeset 54:e75e143b92e7
fix Read/Write missing argument and maybe run on Unity
author | riono <e165729@ie.u-ryukyu.ac.jp> |
---|---|
date | Fri, 14 Jan 2022 20:40:21 +0900 |
parents | bdc364119f30 |
children | b768fffe118c |
files | Christie_net.csproj Test/Example/FizzBuzz/Counter.cs Test/Example/FizzBuzz/FizzBuzz.cs Test/Example/FizzBuzz/StartFizzBuzz.cs daemon/Connection.cs daemon/IncomingTcpConnection.cs daemon/OutboundTcpConnection.cs datagear/RemoteMessage.cs datagear/command/Command.cs datagear/command/PutCommand.cs datagear/command/RemoteTakeCommand.cs |
diffstat | 11 files changed, 66 insertions(+), 44 deletions(-) [+] |
line wrap: on
line diff
--- a/Christie_net.csproj Fri Jan 14 15:46:07 2022 +0900 +++ b/Christie_net.csproj Fri Jan 14 20:40:21 2022 +0900 @@ -3,7 +3,7 @@ <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>netcoreapp6.0</TargetFramework> - <StartupObject>Christie_net.Test.Example.OddEven.StartOddEven</StartupObject> + <StartupObject>Christie_net.Test.Example.FizzBuzz.StartFizzBuzz</StartupObject> </PropertyGroup> <ItemGroup>
--- a/Test/Example/FizzBuzz/Counter.cs Fri Jan 14 15:46:07 2022 +0900 +++ b/Test/Example/FizzBuzz/Counter.cs Fri Jan 14 20:40:21 2022 +0900 @@ -10,7 +10,7 @@ public override void Run(CodeGearManager cgm) { if (num <= 100) { GetDgm("FizzBuzz").Put("num", num); - //cgm.GetLocalDGM().Put("num", num+1); + cgm.GetLocalDGM().Put("num", num+1); //Console.WriteLine(num); cgm.Setup(new Counter()); } else {
--- a/Test/Example/FizzBuzz/FizzBuzz.cs Fri Jan 14 15:46:07 2022 +0900 +++ b/Test/Example/FizzBuzz/FizzBuzz.cs Fri Jan 14 20:40:21 2022 +0900 @@ -18,7 +18,7 @@ } else { Console.WriteLine(num); } - GetDgm("Counter").Put("num", num+1); + //GetDgm("Counter").Put("num", num+1); cgm.Setup(new FizzBuzz()); } }
--- a/Test/Example/FizzBuzz/StartFizzBuzz.cs Fri Jan 14 15:46:07 2022 +0900 +++ b/Test/Example/FizzBuzz/StartFizzBuzz.cs Fri Jan 14 20:40:21 2022 +0900 @@ -15,7 +15,7 @@ counter.Setup(new Counter()); fizzbuzz.Setup(new FizzBuzz()); counter.CreateRemoteDGM("FizzBuzz", "localhost", 10002); - fizzbuzz.CreateRemoteDGM("Counter", "localhost", 10001); + //fizzbuzz.CreateRemoteDGM("Counter", "localhost", 10001); counter.GetLocalDGM().Put("num", 1); } }
--- a/daemon/Connection.cs Fri Jan 14 15:46:07 2022 +0900 +++ b/daemon/Connection.cs Fri Jan 14 20:40:21 2022 +0900 @@ -6,6 +6,7 @@ using Christie_net.codegear; using Christie_net.datagear.command; using Christie_net.Test.Example.RemoteTake; +using MessagePack; namespace Christie_net.daemon { public class Connection { @@ -56,7 +57,7 @@ byte[] buffer = cmd.Convert(); try { - stream.Write(buffer); + stream.Write(buffer,0 , buffer.Length); } catch (Exception e) { Console.WriteLine(e.StackTrace); }
--- a/daemon/IncomingTcpConnection.cs Fri Jan 14 15:46:07 2022 +0900 +++ b/daemon/IncomingTcpConnection.cs Fri Jan 14 20:40:21 2022 +0900 @@ -26,44 +26,56 @@ public void Run() { while (true) { //TODO: Data長がわからないので1024で仮置き → ぴったしで読み込む必要がある - byte[] streamData = new byte[1000000]; - - + // データは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[] data; + + int dataLen; int length = 0; try { - length = connection.stream.Read(streamData); - //Console.WriteLine("call:" + connection.stream.Position); - - } catch (Exception e) { - Console.WriteLine(e.StackTrace); - } + // get RemoteMessage.class size + connection.stream.Read(remoteMessageSizeArray, 0, 1); + int remoteMsglen = MessagePackSerializer.Deserialize<int>(remoteMessageSizeArray); - // データはRemotemessage(Command), length, dataの順で入っている - //int dataLength = connection.socket.Receive(deserializeCommand); - - // Debug - //Console.WriteLine("length:" + length); + remoteMessage = new byte[remoteMsglen]; + + // get RemoteMessage + connection.stream.Read(remoteMessage, 0, remoteMsglen); + RemoteMessage msg = MessagePackSerializer.Deserialize<RemoteMessage>(remoteMessage); + CommandType type = CommandTypeExt.GetCommandTypeFormId(msg.type); - RemoteMessage msg = MessagePackSerializer.Deserialize<RemoteMessage>(streamData); - CommandType type = CommandTypeExt.GetCommandTypeFormId(msg.type); + // Debug + //Console.WriteLine("length:" + msg.key + " " + msg.type); - try { - byte[] data; + //Console.WriteLine("call:" + connection.stream.Position); + + // int dataSize = connection.stream.Read() switch (type) { case CommandType.PUT: - data = msg.data; + // get data size + connection.stream.Read(dataSizeArray, 0, 1); + dataLen = MessagePackSerializer.Deserialize<int>(dataSizeArray); + data = new byte[dataLen]; + + // get data + connection.stream.Read(data, 0, dataLen); + //data = msg.data; try { MessagePackDataGear<object> dg = new MessagePackDataGear<object>(data, Type.GetType(msg.clazz)); - + cgm.GetLocalDGM().Put(msg.key, dg); } catch (TypeLoadException e) { Console.WriteLine(e.StackTrace); } + break; - + case CommandType.REMOTEPEEK: case CommandType.REMOTETAKE: try { @@ -77,10 +89,17 @@ } catch (Exception e) { Console.WriteLine(e); } + break; - + case CommandType.REPLY: // 待っていたwaitlistに渡してcsにセット - data = msg.data; + // get data size + connection.stream.Read(dataSizeArray, 0, 1); + dataLen = MessagePackSerializer.Deserialize<int>(dataSizeArray); + data = new byte[dataLen]; + + // get data + connection.stream.Read(data, 0, dataLen); // data = new byte[MessagePackSerializer.Deserialize<int>(streamData)]; // connection.socket.Receive(data); @@ -92,14 +111,15 @@ } catch (TypeLoadException e) { Console.WriteLine(e.StackTrace); } + break; - + default: break; } } catch (Exception e) { - Console.WriteLine("call: " + e.StackTrace); - } + Console.WriteLine(e.StackTrace); + } } } }
--- a/daemon/OutboundTcpConnection.cs Fri Jan 14 15:46:07 2022 +0900 +++ b/daemon/OutboundTcpConnection.cs Fri Jan 14 20:40:21 2022 +0900 @@ -16,7 +16,6 @@ try { Command cmd; if (connection.sendQueue.TryTake(out cmd)) { - Console.WriteLine("outboud:" + cmd.type); switch (cmd.type) { case CommandType.CLOSE: case CommandType.FINISH:
--- a/datagear/RemoteMessage.cs Fri Jan 14 15:46:07 2022 +0900 +++ b/datagear/RemoteMessage.cs Fri Jan 14 20:40:21 2022 +0900 @@ -12,17 +12,14 @@ public string key; [Key("clazz")] public string clazz; - [Key("data")] - public byte[] data; - + public RemoteMessage(){} // for messagePack - public RemoteMessage(int type, string fromDmgName, string key, string clazz, byte[] data) { + public RemoteMessage(int type, string fromDmgName, string key, string clazz) { this.type = type; this.fromDmgName = fromDmgName; this.key = key; this.clazz = clazz; - this.data = data; } } } \ No newline at end of file
--- a/datagear/command/Command.cs Fri Jan 14 15:46:07 2022 +0900 +++ b/datagear/command/Command.cs Fri Jan 14 20:40:21 2022 +0900 @@ -37,8 +37,8 @@ // for remote public abstract byte[] Convert(); - public RemoteMessage CreateRemoteMessage(byte[] data) { - return new RemoteMessage((int) type, fromDgmName, key, clazz.FullName, data); + public RemoteMessage CreateRemoteMessage() { + return new RemoteMessage((int) type, fromDgmName, key, clazz.FullName); } public void SetDg(Object obj) {
--- a/datagear/command/PutCommand.cs Fri Jan 14 15:46:07 2022 +0900 +++ b/datagear/command/PutCommand.cs Fri Jan 14 20:40:21 2022 +0900 @@ -2,6 +2,7 @@ using System.IO; using Christie_net.datagear.dg; using MessagePack; +using Microsoft.VisualBasic.CompilerServices; namespace Christie_net.datagear.command { public class PutCommand : Command { @@ -17,15 +18,19 @@ MemoryStream stream = new MemoryStream(); try { + byte[] command = MessagePackSerializer.Serialize(CreateRemoteMessage()); + byte[] commandsize = MessagePackSerializer.Serialize(command.Length); byte[] data = new MessagePackDataGear<dynamic>(dg.GetData()).GetMessagePack(); - byte[] command = MessagePackSerializer.Serialize(CreateRemoteMessage(data)); + byte[] datasize = MessagePackSerializer.Serialize(data.Length); // Debug // RemoteMessage msg = MessagePackSerializer.Deserialize<RemoteMessage>(command); // Console.WriteLine("serialize msg:" + msg); - stream.Write(command); - + stream.Write(commandsize, 0, commandsize.Length); + stream.Write(command,0, command.Length); + stream.Write(datasize, 0, datasize.Length); + stream.Write(data, 0, data.Length); } catch (IOException e) { Console.WriteLine(e.StackTrace); }
--- a/datagear/command/RemoteTakeCommand.cs Fri Jan 14 15:46:07 2022 +0900 +++ b/datagear/command/RemoteTakeCommand.cs Fri Jan 14 20:40:21 2022 +0900 @@ -17,10 +17,10 @@ MemoryStream stream = new MemoryStream(); try { - byte[] command = MessagePackSerializer.Serialize(CreateRemoteMessage(null)); + byte[] command = MessagePackSerializer.Serialize(CreateRemoteMessage()); - stream.Write(command); + stream.Write(command, 0, command.Length); stream.Position = 0; } catch (IOException e) {