コード例 #1
0
ファイル: BingoGameServer.cs プロジェクト: d3x0r/xperdex
        void Connected(IAsyncResult iar)
        {
            Socket client = (Socket)iar.AsyncState;

            try
            {
                BingoGameServerSocketState state = new BingoGameServerSocketState();
                client.EndConnect(iar);
                //conStatus.Text = "Connected to: " + client.RemoteEndPoint.ToString();
                state.data         = new byte[4096];
                state.size         = 4096;
                state.reading_size = true;
                client.BeginReceive(state.data, 0, 4, SocketFlags.None, read_complete, state);
            }
            catch (SocketException)
            {
                client.Close();
                socket = null;
                //conStatus.Text = "Error connecting";
            }
        }
コード例 #2
0
ファイル: BingoGameServer.cs プロジェクト: d3x0r/xperdex
        void read_complete(IAsyncResult iar)
        {
            BingoGameServerSocketState state = (BingoGameServerSocketState)iar.AsyncState;
            SocketError error;
            int         to_read = 4;

            int recv = socket.EndReceive(iar, out error);

            if (recv == 0)
            {
                // closed?
                socket.Close();
                socket = null;
                return;
            }
            if (error == SocketError.ConnectionReset)
            {
                socket.Close();
                socket = null;
                return;
            }

            if (state.reading_size)
            {
                to_read            = BitConverter.ToInt32(state.data, 0);
                state.reading_size = false;
            }
            else
            {
                string stringData = Encoding.ASCII.GetString(state.data, 0, recv);
                //System.Xml.XPath.XPathNavigator xnav = new XPathNavigator();
                XmlDocument xd = new XmlDocument();
                xd.LoadXml(stringData);
                XPathNavigator xn = xd.CreateNavigator();
                bool           okay;
                //XPathNavigator xn2 = xn.CreateNavigator();
                xn.MoveToFirst();
                for (okay = xn.MoveToFirstChild(); okay; okay = xn.MoveToNext())
                {
                    if (xn.NodeType == XPathNodeType.Element)
                    {
                        String command_data = null;
                        String called       = null;
                        String uncalled     = null;
                        switch (xn.Name)
                        {
                        case "Command":
                            bool need_do_command = true;
                            BingoGameServerProtocol.Commands current_command = BingoGameServerProtocol.Commands.None;
                            bool okay2;
                            bool everokay = false;
                            for (okay2 = xn.MoveToFirstAttribute(); okay2; okay2 = xn.MoveToNextAttribute())
                            {
                                switch (xn.Name)
                                {
                                case "CODE":

                                    break;
                                }
                            }
                            break;
                        }
                    }
                }
                state.reading_size = true;
            }
            socket.BeginReceive(state.data, 0, to_read, SocketFlags.None, read_complete, null);
        }