当前位置: 首页>>代码示例>>C#>>正文


C# Data.ToByte方法代码示例

本文整理汇总了C#中Data.ToByte方法的典型用法代码示例。如果您正苦于以下问题:C# Data.ToByte方法的具体用法?C# Data.ToByte怎么用?C# Data.ToByte使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Data的用法示例。


在下文中一共展示了Data.ToByte方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: SendMessage

        /*
          * Send a message to the remote party.
          */
        private void SendMessage(Command cmd, EndPoint sendToEP)
        {
            try
            {
                //Create the message to send.
                Data msgToSend = new Data();

                msgToSend.strName = Nickname;   //Name of the user.
                msgToSend.cmdCommand = cmd;         //Message to send.
                msgToSend.vocoder = vocoder;        //Vocoder to be used.

                byte[] message = msgToSend.ToByte();

                //Send the message asynchronously.
                clientSocket.BeginSendTo(message, 0, message.Length, SocketFlags.None, sendToEP, new AsyncCallback(OnSend), null);
            }
            catch (Exception ex)
            {
                cGlobalVars.AddLogChat("VoiceChat-SendMessage > " + ex.Message);
                //MessageBox.Show(ex.Message, "VoiceChat-SendMessage ()", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
开发者ID:netonjm,项目名称:VoiceChat,代码行数:25,代码来源:cChatEngine.cs

示例2: OnReceive

        private void OnReceive(IAsyncResult ar)
        {
            try
            {
                Socket clientSocket = (Socket)ar.AsyncState;

                clientSocket.EndReceive(ar);
                //Transform the array of bytes received from the user into an
                //intelligent form of object Data
                Data msgReceived = new Data(byteData);

                //We will send this object in response the users request
                Data msgToSend = new Data();

                byte[] message = new byte[1024];

                msgToSend = msgReceived;

                switch (msgReceived.function)
                {
                    case Function.Login:

                        //When a user logs in to the server then we add her to our
                        //list of clients

                        ClientInfo clientInfo = new ClientInfo();
                        clientInfo.socket = clientSocket;
                        clientInfo.strName = msgReceived.strName;

                        clientList.Add(clientInfo);

                        //Set the text of the message that we will broadcast to all users
                        msgToSend.objects = new object[] {"<<<" + msgReceived.strName + " has joined the room>>>"};
                        break;

                    case Function.Logout:

                        //When a user wants to log out of the server then we search for her
                        //in the list of clients and close the corresponding connection

                        int nIndex = 0;
                        foreach (ClientInfo client in clientList)
                        {
                            if (client.socket == clientSocket)
                            {
                                clientList.RemoveAt(nIndex);
                                break;
                            }
                            ++nIndex;
                        }

                        clientSocket.Close();

                        msgToSend.objects = new object[] {"<<<" + msgReceived.strName + " has left the room>>>"};
                        break;
                }

                if (msgToSend.function != Function.List)   //List messages are not broadcasted
                {
                    Array.Copy(msgToSend.ToByte(), message, msgToSend.ToByte().Length);

                    foreach (ClientInfo clientInfo in clientList)
                    {
                        if (clientInfo.socket != clientSocket ||
                            msgToSend.function != Function.Login)
                        {
                            //Send the message to all users
                            clientInfo.socket.BeginSend(message, 0, message.Length, SocketFlags.None,
                                new AsyncCallback(OnSend), clientInfo.socket);
                        }
                    }
                }

                //If the user is logging out then we need not listen from her
                if (msgReceived.function != Function.Logout)
                {
                    //Start listening to the message send by the user
                    clientSocket.BeginReceive(byteData, 0, byteData.Length, SocketFlags.None, new AsyncCallback(OnReceive), clientSocket);
                }
            }
            catch (Exception exc) { Debug.WriteLine(exc.ToString()); }
        }
开发者ID:sunenilausen,项目名称:SocketsNetwork,代码行数:82,代码来源:ServerSocket.cs

示例3: SendFunction

        public void SendFunction(Function function, params object[] objects)
        {
            try
            {
                //Fill the info for the message to be send
                Data msgToSend = new Data();

                msgToSend.strName = strName;
                msgToSend.function = function;
                msgToSend.objects = objects;

                byte[] byteData = new byte[1024];
                Array.Copy(msgToSend.ToByte(), byteData, msgToSend.ToByte().Length);

                //Send it to the server
                Send(clientSocket, byteData);
                sendDone.WaitOne();
            }
            catch (Exception exc) { Debug.WriteLine(exc.ToString()); }
        }
开发者ID:sunenilausen,项目名称:SocketsNetwork,代码行数:20,代码来源:ClientSocket.cs

示例4: SendMessage

        private void SendMessage(Command cmd, EndPoint sendToEP, string _txt = null)
        {
            try
            {
                //Create the message to send.
                LogLine("Sending...");
                Data msgToSend = new Data();

                msgToSend.strName = Nick.Text;   //Name of the user.
                msgToSend.cmdCommand = cmd;         //Message to send.
                msgToSend.vocoder = vocoder;        //Vocoder to be used.
                msgToSend.txt = _txt;

                byte[] message = msgToSend.ToByte();

                //Send the message asynchronously.
                clientSocket.BeginSendTo(message, 0, message.Length, SocketFlags.None, sendToEP, new AsyncCallback(OnSend), null);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Ошибка отправки сообщения | Fenazy", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
开发者ID:iRadioMan,项目名称:Fenazy,代码行数:23,代码来源:Form1.cs

示例5: OnConnect

        private void OnConnect(IAsyncResult ar)
        {
            try
            {
                clientSocket.EndConnect(ar);

                //We are connected so we login into the server
                Data msgToSend = new Data();
                msgToSend.strName = strName;
                msgToSend.function = Function.Login;
                msgToSend.objects = new object[] {null};

                byte[] b = msgToSend.ToByte();

                //Send the message to the server
                clientSocket.BeginSend(b, 0, b.Length, SocketFlags.None, new AsyncCallback(OnSend), null);
                SendFunction(Function.DebugMessage, strName + " has connected.");
            }
            catch (Exception exc) { Debug.WriteLine(exc.ToString()); }
        }
开发者ID:sunenilausen,项目名称:SocketsNetwork,代码行数:20,代码来源:ClientSocket.cs


注:本文中的Data.ToByte方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。