示例#1
0
    public static void Main(string[] argv)
    {
        if (false)
        {
            var desc  = dx.Socket.Ex.CreateDescTemp("くみれい");
            var bytes = dx.Socket.Ex.ToByteRevenge(desc);
            Console.WriteLine($"encoded: {bytes[0]}");
            var desc02 = dx.Socket.Ex.FromByteDataRevenge(bytes);
            Console.WriteLine($"decoded: {desc.header.dataType.ToString()}, {dx.Socket.Ex.FromDescTemp(desc)}");
            return;
        }
        // C# のコマンドライン引数は 0 はじまり
        // Mode mode = (Mode)Enum.Parse(typeof(Mode), argv[0], true);
        Side side = (Side)Enum.Parse(typeof(Side), argv[1], true);

        switch (side)
        {
        case Side.Client:
        {
            Client client = new Client();
            ExecuteClientManual(client, int.Parse(argv[2]), argv[3]);
        } break;

        case Side.Server:
        {
            Server server = new Server();
            ExecuteServerManual(server, int.Parse(argv[2]));
        } break;
        }
    }
示例#2
0
    public static void ExecuteClient(Client client, int portNumber, string ipAddressStr)
    {
        client.Initialize(portNumber, ipAddressStr);
        client.CreateSocket();
        client.RequestConnection();

        client.Send(Encoding.UTF8.GetBytes("くみれい"));
        client.Receive();
        client.Send(Encoding.UTF8.GetBytes("ライきり"));
        client.Receive();
        client.Send(Encoding.UTF8.GetBytes("はなまいひめ"));

        client.ShutdownAndClose();
    }
示例#3
0
    public static void ExecuteClientManual(Client client, int portNumber, string ipAddressStr)
    {
        client.Initialize(portNumber, ipAddressStr);
        client.CreateSocket();
        client.RequestConnection();

        const bool isReceiveHidouki = false;

        if (isReceiveHidouki)
        {
            client.BeginReceive();
        }
        while (isReceiveHidouki)
        {
            Console.Write("please enter: ");
            var str = Console.ReadLine();
            Console.Write("うんうん、それもまたアイカツだね");
            if (str == "quit")
            {
                client.EndReceive();
                break;
            }
        }
        while (!isReceiveHidouki)
        {
            Console.Write("please enter: ");
            var str = Console.ReadLine();
            if (str == dx.Socket.Constant.EndOfMessages)
            {
                client.SendWithHeaderString(LogLevel.Info, "Cs.Manual.Client.String", str);
                // client.Send(Encoding.UTF8.GetBytes(str));
                Console.WriteLine("See you...");
                break;
            }
            else if (str.Length == 0)
            {
                Console.WriteLine("receive...");
                var msg = client.Receive();
                if (msg == dx.Socket.Constant.EndOfMessages)
                {
                    Console.WriteLine("See you...");
                    break;
                }
                else
                {
                    Console.WriteLine($"received: {msg}");
                }
            }
            else
            {
                if (str.EndsWith(".png"))
                {
                    str = "/Users/kazuaki/Documents/develop/Network/SocketTest02/" + str;
                    if (System.IO.File.Exists(str))
                    {
                        Console.WriteLine($"Image file is Exist! {str}");
                        client.SendWithHeaderImagePath(LogLevel.Debug, "Cs.Manual.Client.ImagePath", str);
                    }
                    else
                    {
                        Console.WriteLine($"Image file is not exist! {str}");
                    }
                }
                else if (str.Contains("."))
                {
                    float value = float.Parse(str);
                    client.SendWithHeaderFloat(LogLevel.Info, "Cs.Manual.Client.Float", value);
                }
                else if (str.Contains("0"))
                {
                    int value = int.Parse(str);
                    client.SendWithHeaderInt(LogLevel.Info, "Cs.Manual.Client.Int", value);
                }
                else
                {
                    client.SendWithHeaderString(LogLevel.Info, "Cs.Manual.Client.String", str);
                }
                Console.WriteLine("send...");
                // client.Send(Encoding.UTF8.GetBytes(str));
            }
        }

        client.ShutdownAndClose();
    }