/// <summary> /// 负责处理线程消息 /// </summary> /// <param name="msg"></param> /// <param name="obj1"></param> void MsgProc(string id, int msg, object obj1) { switch (msg) { case MSG_UPADTE_COUNT: lblClientState.Text = "客户端数:" + ClientList.GetClientCount(); break; case MSG_ACCEPT: lblClientState.Text = "客户端数:" + ClientList.GetClientCount(); break; case MSG_SEND_SUCCEED: Tool.Log("发送成功(" + (string)obj1 + ")"); break; case MSG_SEND_FAIL: Tool.Log("发送失败"); break; case MSG_RESPONSE_SUCCEED: //lblSendState.Text = "服务器响应成功"; break; case MSG_RESPONSE_FAIL: //lblSendState.Text = "服务器响应失败"; break; case MSG_EXCEPTION: //lblSendState.Text = "连接异常"; break; case MSG_RECEIVE_SUCCEED: Tool.Log("接收文件成功(" + (string)obj1 + ")"); break; case MSG_RECEIVE_FAIL: Tool.Log("接收文件失败(" + (string)obj1 + ")"); break; // 收到文字 // TODO 协议处理 case MSG_RECEIVE: //Tool.Log("接收文字(" + (string)obj1 + ")"); switch (Protocol.GetCommand((string)obj1)) { case Protocol.PAUSE: player.Ctlcontrols.pause(); playing = false; SendButtonState(); break; case Protocol.PLAY: player.Ctlcontrols.play(); playing = true; //SendName();//必要? SendButtonState(); break; case Protocol.INIT: SendInitData(ClientList.getSocket(id)); break; case Protocol.TURN_DOWN: player.settings.volume -= 10; if (player.settings.volume < 0) { player.settings.volume = 0; } SendSound(ClientList.getSocket(id)); break; case Protocol.TURN_UP: player.settings.volume += 10; if (player.settings.volume > 100) { player.settings.volume = 100; } SendSound(ClientList.getSocket(id)); break; case Protocol.SHUT_DOWN: Other.CloseComputer(); break; case Protocol.PROGRESS: string strProgress = Protocol.GetContent(); int progress; try { progress = Int32.Parse(strProgress); } catch { MessageBox.Show("数字出错"); return; } int total = (int)player.currentMedia.duration; player.Ctlcontrols.currentPosition = progress / 100.0 * total; break; case Protocol.LAST: PreMusic(); SendName(); playing = true; break; case Protocol.NEXT: NextMusic(); SendName(); playing = true; break; case Protocol.SEND_LIST: SendList(ClientList.getSocket(id)); break; case Protocol.PLAY_NAME: string name = Protocol.GetContent(); player.URL = name; player.Ctlcontrols.play(); //列表选中对应的歌曲 for (int i = 0; i < lbMusic.Items.Count; i++) { //MessageBox.Show(lbMusic.Items[i].ToString()+"和"+name); if (lbMusic.Items[i].ToString().Equals(Path.GetFileNameWithoutExtension(name))) { m_curMusic = i; lbMusic.SelectedIndex = i; } } SendName(); break; case Protocol.CLOSE_CLIENT: lblClientState.Text = "客户端数:" + ClientList.GetClientCount(); ClientList.Remove(id); break; } break; } }
private void btn_Click(object sender, EventArgs e) { Other.CloseComputer(); }
//负责处理线程消息 /// <summary> /// 负责处理线程消息 /// </summary> /// <param name="msg"></param> /// <param name="obj1"></param> void MsgProc(int msg, object obj1) { switch (msg) { case MSG_ACCEPT: //MessageBox.Show((string)obj1); //lblServerState.Text = "收到消息"; lblClientState.Text = "客户端(" + (string)obj1 + ")已连接"; haveConnect = true; //SendInitData(); break; case MSG_SEND_SUCCEED: lblMsg.Text = "发送成功(" + (string)obj1 + ")"; break; case MSG_SEND_FAIL: lblMsg.Text = "发送失败"; break; case MSG_RESPONSE_SUCCEED: //lblSendState.Text = "服务器响应成功"; break; case MSG_RESPONSE_FAIL: //lblSendState.Text = "服务器响应失败"; break; case MSG_EXCEPTION: //lblSendState.Text = "连接异常"; break; case MSG_RECEIVE_SUCCEED: lblMsg.Text = "接收文件成功(" + (string)obj1 + ")"; break; case MSG_RECEIVE_FAIL: lblMsg.Text = "接收文件失败(" + (string)obj1 + ")"; break; // 收到文字 // TODO 协议处理 case MSG_RECEIVE: lblMsg.Text = "接收文字(" + (string)obj1 + ")"; switch (Protocol.GetCommand((string)obj1)) { case Protocol.STOP: player.close(); break; case Protocol.PAUSE: player.Ctlcontrols.pause(); break; case Protocol.PLAY: player.Ctlcontrols.play(); break; case Protocol.SHUT_DOWN: Other.CloseComputer(); break; case Protocol.PROGRESS: string strProgress = Protocol.GetContent(); int progress; try { progress = Int32.Parse(strProgress); } catch { MessageBox.Show("数字出错"); return; } int total = (int)player.currentMedia.duration; player.Ctlcontrols.currentPosition = progress / 100.0 * total; break; case Protocol.LAST: PreMusic(); break; case Protocol.NEXT: NextMusic(); break; case Protocol.SEND_LIST: SendList(); break; case Protocol.PLAY_NAME: string name = Protocol.GetContent(); player.URL = name; player.Ctlcontrols.play(); break; case Protocol.CLOSE_CLIENT: lblClientState.Text = "客户端已断开连接"; haveConnect = false; break; } break; } }