Beispiel #1
0
        public static (bool, string) SendRecv(string body)
        {
            if (BeforeSetAddress)
            {
                return(false, string.Empty);
            }
            Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            socket.Connect(Address, Port);
            if (!socket.Connected)
            {
                while (!socket.Connected)
                {
                    socket = Reconnect(socket);
                }
            }
            try
            {
                var withHeader = HeaderProtocol.MakeHeader(body, true);
                var(s, r, recvMsg) = Connection.SendAndRecvMessage(withHeader, socket);
                socket.Close();
                return(r, recvMsg);
            }
            catch (Exception)
            {
                return(false, string.Empty);
            }
        }
        public void ああああ(string input, bool exp)
        {
            var withHeader = HeaderProtocol.MakeHeader(input, true);

            var(s, r, m) = Connection.SendAndRecvMessage(withHeader, _socket);
            Console.WriteLine($"{s} {r} {m}");
        }
        public string MakeSendMessage(string receivedMessage)
        {
            var message = JsonConvert.DeserializeObject <ClientMessage>(receivedMessage);

            var(methodSuccess, sendMessage) = message switch
            {
                CreatePlayerMessage cr => CreatePlayer(cr),
                CloseCreateMessage cl => CloseCreate(cl),
                GetMatchInfoMessage gm => GetMatchInfo(gm),
                GetAllMatchesMessage _ => GetAllMatches(),
                DiceMessage dm => ThrowDice(dm),
                GetStartedMatchMessage gsm => GetStatedMatch(gsm),
                GetRankingMessage gr => GetRanking(gr),
                GetMatchViewImageMessage gmv => GetMatchView(gmv),
                _ => throw new NotImplementedException()
            };

            return(HeaderProtocol.MakeHeader(sendMessage, methodSuccess));
        }