private static void Receiver_MessageReceived(object sender, UdpReceivedEventArgs args) { byte[] buff = args.Buffer; // 一行将 byte[] 转为字符串 string rec = String.Join(",", buff.Select(b => b.ToString()).ToArray()); Console.WriteLine(rec); }
/// <summary> /// This function will be called after receiving a Packet. /// And copy data to the buffer and Call another function to process messages in the packet. /// </summary> /// <param name="sender">--</param> /// <param name="e">received message</param> void UdpPort_AfterReceive(object sender, UdpReceivedEventArgs e) { int len = e.date.Length; for (int i = 0; i < len; i++) { //Copy this.Rx_Buff[i] = e.date[i]; } this.ProcessPacket(len); }
// ---------------------------------------------------------------- private void OnUdpReceived(object sender, UdpReceivedEventArgs e) { if (e.message.Length <= 0) { return; } string[] dataStrings = e.message.Split('_'); string cmd = dataStrings[0]; if (dataStrings.Length == 1) { // Hide countdown (nf = No face) if (cmd == "nf") { ScheduleTask(new Task(delegate { countdownString = ""; texts_countdown.ForEach(tm => tm.text = ""); })); } else if (cmd == "resume") { YucoDebugger.instance.Log("OF resume game...", "OnUdpReceived", "GameRoot"); // ****** TO-DO: resume current status } } else if (dataStrings.Length > 1) { // Count down if (cmd == "cd") { screensaverTimer.ResetIdleTime(); string duration = dataStrings[1]; ScheduleTask(new Task(delegate { if (countdownString != duration) { countdownString = duration; audioSrc.PlayOneShot(audio_countdown); } texts_countdown.ForEach(tm => tm.text = duration); })); } // Photo taken with Player ID else if (cmd == "tk") { screensaverTimer.ResetIdleTime(); int playerId = 1; int.TryParse(dataStrings[1], out playerId); playerId += 1; //Debug.Log("cmd = " + cmd + "_" + playerId.ToString()); ScheduleTask(new Task(delegate { audioSrc.PlayOneShot(audio_camShutter); if (gameMode == GameMode.GAME1) { UIManager.HideUiElement("G1_TakePhoto", "FacialGame"); UIManager.ShowUiElement("G1_ConfirmPhoto", "FacialGame"); } else if (gameMode == GameMode.GAME2) { UIManager.HideUiElement("G2_TakePhotoP" + playerId.ToString(), "FacialGame"); UIManager.ShowUiElement("G2_ConfirmPhotoP" + playerId.ToString(), "FacialGame"); } else if (gameMode == GameMode.GAME3) { UIManager.HideUiElement("G3_TakePhoto", "FacialGame"); UIManager.ShowUiElement("G3_ConfirmPhoto", "FacialGame"); } })); } } }
private static void Receiver_MessageRecieved(object sender, UdpReceivedEventArgs e) { Logger.Info($"buff: {String.Join(",", e.Buffer.Select(p => p.ToString()).ToArray())}"); }