Mercurial > hg > Database > Christie-sharp
changeset 13:e4b46d4ef79c
connection.cs fin
author | riono <e165729@ie.u-ryukyu.ac.jp> |
---|---|
date | Thu, 19 Nov 2020 23:52:29 +0900 |
parents | 9129c437b1a3 |
children | 277dd59bf1e2 |
files | daemon/Connection.cs datagear/command/Command.cs |
diffstat | 2 files changed, 17 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/daemon/Connection.cs Thu Nov 19 16:46:00 2020 +0900 +++ b/daemon/Connection.cs Thu Nov 19 23:52:29 2020 +0900 @@ -34,16 +34,28 @@ ((IPEndPoint) socket.RemoteEndPoint).Port.ToString()); } + /// <summary> + /// socketを閉じる + /// </summary> public void Close() { + socket.Shutdown(SocketShutdown.Both); socket.Close(); } + /// <summary> + /// commandの実装に従ってbyte配列に変換し接続先に書き込む + /// </summary> + /// <param name="cmd"></param> public void Write(Command cmd) { - MemoryStream stream = cmd.Convert(); + byte[] stream = cmd.Convert(); - // while (stream.) { - // - // } + try { + while (stream.Length > 0) { + socket.Send(stream); + } + } catch (Exception e) { + Console.WriteLine(e.StackTrace); + } } } } \ No newline at end of file
--- a/datagear/command/Command.cs Thu Nov 19 16:46:00 2020 +0900 +++ b/datagear/command/Command.cs Thu Nov 19 23:52:29 2020 +0900 @@ -33,7 +33,7 @@ public abstract void Execute(); // for remote - public abstract MemoryStream Convert(); + public abstract byte[] Convert(); // public RemoteMassage CreateRemoteMessage() { // return new RemoteMassage(type.id);