changeset 11:1f7d4f168b89

socket test
author riono <e165729@ie.u-ryukyu.ac.jp>
date Thu, 19 Nov 2020 03:05:28 +0900
parents 5f726dc31874
children 9129c437b1a3
files Christie_net.csproj Program.cs RewritingTest/ParseAddress.cs RewritingTest/Program.cs RewritingTest/SocketIPPortCheck.cs codegear/InputDataGear.cs daemon/Connection.cs datagear/DataGearManager.cs datagear/command/Command.cs datagear/command/CommandBuilder.cs
diffstat 10 files changed, 209 insertions(+), 43 deletions(-) [+]
line wrap: on
line diff
--- a/Christie_net.csproj	Tue Nov 17 19:34:44 2020 +0900
+++ b/Christie_net.csproj	Thu Nov 19 03:05:28 2020 +0900
@@ -3,6 +3,7 @@
     <PropertyGroup>
         <OutputType>Exe</OutputType>
         <TargetFramework>netcoreapp3.1</TargetFramework>
+        <StartupObject>SocketIPPortCheck</StartupObject>
     </PropertyGroup>
 
     <ItemGroup>
--- a/Program.cs	Tue Nov 17 19:34:44 2020 +0900
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,11 +0,0 @@
-using System;
-
-namespace Christie_net {
-internal class Program {
-    //[Peek] Test testindex;
-
-    private static void Main(string[] args) {
-        Console.WriteLine("Hello World!");
-    }
-}
-}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RewritingTest/ParseAddress.cs	Thu Nov 19 03:05:28 2020 +0900
@@ -0,0 +1,66 @@
+using System;
+using System.Net;
+
+class ParseAddress
+{
+
+    private static void Main(string[] args)
+    {
+        string IPaddress;
+
+        if (args.Length == 0)
+        {
+            Console.WriteLine("Please enter an IP address.");
+            Console.WriteLine("Usage:   >cs_parse any IPv4 or IPv6 address.");
+            Console.WriteLine("Example: >cs_parse 127.0.0.1");
+            Console.WriteLine("Example: >cs_parse 0:0:0:0:0:0:0:1");
+            return;
+        }
+        else
+        {
+            IPaddress = args[0];
+        }
+
+        // Get the list of the IPv6 addresses associated with the requested host.
+        Parse(IPaddress);
+    }
+
+    // This method calls the IPAddress.Parse method to check the ipAddress
+    // input string. If the ipAddress argument represents a syntatically correct IPv4 or
+    // IPv6 address, the method displays the Parse output into quad-notation or
+    // colon-hexadecimal notation, respectively. Otherwise, it displays an
+    // error message.
+    private static void Parse(string ipAddress)
+    {
+        try
+        {
+            // Create an instance of IPAddress for the specified address string (in
+            // dotted-quad, or colon-hexadecimal notation).
+            IPAddress address = IPAddress.Parse(ipAddress);
+
+            // Display the address in standard notation.
+            Console.WriteLine("Parsing your input string: " + "\"" + ipAddress + "\"" + " produces this address (shown in its standard notation): "+ address.ToString());
+        }
+
+        catch(ArgumentNullException e)
+        {
+            Console.WriteLine("ArgumentNullException caught!!!");
+            Console.WriteLine("Source : " + e.Source);
+            Console.WriteLine("Message : " + e.Message);
+        }
+
+        catch(FormatException e)
+        {
+            Console.WriteLine("FormatException caught!!!");
+            Console.WriteLine("Source : " + e.Source);
+            Console.WriteLine("Message : " + e.Message);
+        }
+
+        catch(Exception e)
+        {
+            Console.WriteLine("Exception caught!!!");
+            Console.WriteLine("Source : " + e.Source);
+            Console.WriteLine("Message : " + e.Message);
+        }
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RewritingTest/Program.cs	Thu Nov 19 03:05:28 2020 +0900
@@ -0,0 +1,11 @@
+using System;
+
+namespace Christie_net {
+internal class Program {
+    //[Peek] Test testindex;
+
+    private static void Main(string[] args) {
+        Console.WriteLine("Hello World!");
+    }
+}
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RewritingTest/SocketIPPortCheck.cs	Thu Nov 19 03:05:28 2020 +0900
@@ -0,0 +1,92 @@
+using System;
+using System.Net;
+using System.Net.Sockets;
+
+// socketを作成してIPとportを取得する 作動にはListenerが必要
+class SocketIPPortCheck {
+    public void SetSocket() {
+        IPHostEntry host = Dns.GetHostEntry("localhost");
+        IPAddress ipAddress = host.AddressList[0];
+        //IPAddress ipAddress = IPAddress.Parse("127.0.0.1");
+        IPEndPoint remoteEP = new IPEndPoint(ipAddress, 11000);
+
+        // Create a TCP/IP  socket.    
+        Socket sender = new Socket(ipAddress.AddressFamily,
+            SocketType.Stream, ProtocolType.Tcp);
+
+        sender.Connect(remoteEP);
+
+        Console.WriteLine(Dns.GetHostEntry(((IPEndPoint)sender.RemoteEndPoint).Address.ToString()).HostName + ":" +
+                          ((IPEndPoint) sender.RemoteEndPoint).Port.ToString());
+    }
+
+    private static void Main(string[] args) {
+        SocketIPPortCheck check = new SocketIPPortCheck();
+        check.SetSocket();
+    }
+}
+
+// Listenerのコード
+// using System;
+// using System.Net;
+// using System.Net.Sockets;
+// using System.Text;
+//
+// // Socket Listener acts as a server and listens to the incoming   
+// // messages on the specified port and protocol.  
+// public class SocketListener {
+//     public static int Main (String[] args) {
+//         StartServer ();
+//         return 0;
+//     }
+//
+//     public static void StartServer () {
+//         // Get Host IP Address that is used to establish a connection  
+//         // In this case, we get one IP address of localhost that is IP : 127.0.0.1  
+//         // If a host has multiple addresses, you will get a list of addresses  
+//         IPHostEntry host = Dns.GetHostEntry ("localhost");
+//         IPAddress ipAddress = host.AddressList[0];
+// 	//IPAddress ipAddress = IPAddress.Parse("127.0.0.1");
+// 	IPEndPoint localEndPoint = new IPEndPoint (ipAddress, 11000);
+//
+//         try {
+//
+//             // Create a Socket that will use Tcp protocol      
+//             Socket listener = new Socket (ipAddress.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
+//             // A Socket must be associated with an endpoint using the Bind method  
+//             listener.Bind (localEndPoint);
+//             // Specify how many requests a Socket can listen before it gives Server busy response.  
+//             // We will listen 10 requests at a time  
+//             listener.Listen (10);
+//
+//             Console.WriteLine ("Waiting for a connection...");
+//             Socket handler = listener.Accept ();
+//
+//             // Incoming data from the client.    
+//             string data = null;
+//             byte[] bytes = null;
+//
+//             while (true) {
+//                 bytes = new byte[1024];
+//                 int bytesRec = handler.Receive (bytes);
+//                 data += Encoding.ASCII.GetString (bytes, 0, bytesRec);
+//                 if (data.IndexOf ("<EOF>") > -1) {
+//                     break;
+//                 }
+//             }
+//
+//             Console.WriteLine ("Text received : {0}", data);
+//
+//             byte[] msg = Encoding.ASCII.GetBytes (data);
+//             handler.Send (msg);
+//             handler.Shutdown (SocketShutdown.Both);
+//             handler.Close ();
+//         } catch (Exception e) {
+//             Console.WriteLine (e.ToString ());
+//         }
+//
+//         Console.WriteLine ("\n Press any key to continue...");
+//         Console.ReadKey ();
+//     }
+//}
+
--- a/codegear/InputDataGear.cs	Tue Nov 17 19:34:44 2020 +0900
+++ b/codegear/InputDataGear.cs	Thu Nov 19 03:05:28 2020 +0900
@@ -7,7 +7,7 @@
 namespace Christie_net.codegear {
 public class InputDataGear {
     public CodeGear cg;
-    public CodeGearManager cgm;
+    //public CodeGearManager cgm;
     private int count;
     public ConcurrentDictionary<string, DataGear<Type>> inputValue = new ConcurrentDictionary<string, DataGear<Type>>();
 
@@ -15,17 +15,17 @@
         this.cg = cg;
     }
 
-    private void FinishInput(CodeGearManager cgm, List<Command> commandList) {
-        this.cgm = cgm;
-        count = commandList.Count;
-
-        if (count == 0) SubmitCG();
-
-        foreach (Command cm in commandList) cgm.GetDGM(cm.toDgmName).RunCommand(cm);
-    }
+    // private void FinishInput(CodeGearManager cgm, List<Command> commandList) {
+    //     this.cgm = cgm;
+    //     count = commandList.Count;
+    //
+    //     if (count == 0) SubmitCG();
+    //
+    //     foreach (Command cm in commandList) cgm.GetDGM(cm.toDgmName).RunCommand(cm);
+    // }
 
     public void SetInputs(string key, DataGear<Type> dg) {
-        inputValue.AddOrUpdate(key, dg);
+        //inputValue.AddOrUpdate(key, dg);
     }
 }
 }
\ No newline at end of file
--- a/daemon/Connection.cs	Tue Nov 17 19:34:44 2020 +0900
+++ b/daemon/Connection.cs	Thu Nov 19 03:05:28 2020 +0900
@@ -1,6 +1,7 @@
 using System;
 using System.Collections.Concurrent;
 using System.IO;
+using System.Net;
 using System.Net.Sockets;
 using Christie_net.datagear.command;
 
@@ -8,15 +9,15 @@
 public class Connection {
     public Socket socket;
     public string name;
-    public CodeGearManager cgm;
+    //public CodeGearManager cgm;
     public ConcurrentQueue<Command> sendQueue = new ConcurrentQueue<Command>();
     public bool sendManager = true;
     private object syncObject = new object();
     
-    public Connection(Socket socket, CodeGearManager cgm) {
-        this.socket = socket;
-        this.cgm = cgm;
-    }
+    // public Connection(Socket socket, CodeGearManager cgm) {
+    //     this.socket = socket;
+    //     this.cgm = cgm;
+    // }
     
     public Connection(){}
 
@@ -24,20 +25,25 @@
         sendQueue.Enqueue(cmd);
     }
 
+    /// <summary>
+    /// socketが接続しているhostnameとそのport番号を返す
+    /// </summary>
+    /// <returns></returns>
     public string GetInfoString() {
-        return socket.
+        return (Dns.GetHostEntry(((IPEndPoint) socket.RemoteEndPoint).Address.ToString()).HostName + ":" +
+                ((IPEndPoint) socket.RemoteEndPoint).Port.ToString());
     }
 
     public void Close() {
-        socket
+        //socket
     }
 
     public void Write(Command cmd) {
         MemoryStream stream = cmd.Convert();
 
-        while (stream.) {
-            
-        }
+        // while (stream.) {
+        //     
+        // }
     }
 }
 }
\ No newline at end of file
--- a/datagear/DataGearManager.cs	Tue Nov 17 19:34:44 2020 +0900
+++ b/datagear/DataGearManager.cs	Thu Nov 19 03:05:28 2020 +0900
@@ -5,7 +5,7 @@
 namespace Christie_net.datagear {
 public abstract class DataGearManager {
     protected DataGears dataGears = new DataGears();
-    public WaitList WaitList = new WaitList();
+    //public WaitList WaitList = new WaitList();
     public abstract void put(string key, object data);
     public abstract void runCommand(Command cm);
     public abstract void resolveWaitCommand(string key, DataGear<Type> dg);
--- a/datagear/command/Command.cs	Tue Nov 17 19:34:44 2020 +0900
+++ b/datagear/command/Command.cs	Thu Nov 19 03:05:28 2020 +0900
@@ -13,7 +13,7 @@
     public CodeGear cg; // for localtake
     public DataGear<object> dg; // for put/localtake/reply
     public Type clazz; // for remote
-    public Connection connection = null; // for reply
+    //public Connection connection = null; // for reply
 
     public Command(CommandBuilder cb) {
         this.type = cb.type;
@@ -24,7 +24,7 @@
         this.cg = cb.cg;
         this.dg = cb.dg;
         this.clazz = cb.clazz;
-        this.connection = cb.connection;
+        //this.connection = cb.connection;
     }
 
     // instead of any Constoractor args
@@ -35,18 +35,19 @@
     // for remote
     public abstract MemoryStream Convert();
 
-    public RemoteMassage CreateRemoteMessage() {
-        return new RemoteMassage(type.id);
-    }
+    // public RemoteMassage CreateRemoteMessage() {
+    //     return new RemoteMassage(type.id);
+    // }
 
     public void SetDg(Object obj) {
         this.dg.SetData(obj);
     }
 
     public override string ToString() {
-        return "Command : type = " + type.commandType + ", key = " + key + "toDgmName = " + toDgmName +
-               " fromDgmName = " + fromDgmName + " cgmID = " + cgmID + " cg = " + cg + " dg = " + dg + " clazz = " +
-               clazz + "connection = " + connection;
+        // return "Command : type = " + type.commandType + ", key = " + key + "toDgmName = " + toDgmName +
+        //        " fromDgmName = " + fromDgmName + " cgmID = " + cgmID + " cg = " + cg + " dg = " + dg + " clazz = " +
+        //        clazz + "connection = " + connection;
+        return null;
     }
 }
 }
\ No newline at end of file
--- a/datagear/command/CommandBuilder.cs	Tue Nov 17 19:34:44 2020 +0900
+++ b/datagear/command/CommandBuilder.cs	Thu Nov 19 03:05:28 2020 +0900
@@ -12,9 +12,9 @@
     protected internal CodeGear cg = null; // for localtake
     protected internal DataGear<object> dg = null; // for put/localtake/reply
     protected internal Type clazz = null; // for remote
-    protected internal Connection connection = null; // for reply
+    //protected internal Connection connection = null; // for reply
     
-    private CommandFactory factory = new CommandFactory();
+    //private CommandFactory factory = new CommandFactory();
 
     public CommandBuilder init(CommandTypeEtx type) {
         this.type = type;
@@ -25,7 +25,7 @@
         this.cg = null;
         this.dg = null;
         this.clazz = null;
-        this.connection = null;
+        //this.connection = null;
         return this;
     }