本文整理汇总了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);
}
}
示例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()); }
}
示例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()); }
}
示例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);
}
}
示例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()); }
}