public void SendAcceptUser(string ipClient) { if (ipClient != String.Empty) { ServerReponse serverReponse = new ServerReponse(); serverReponse.Type = ServerResponseType.SendAcceptUser; serverReponse.DataResponse = ipClient; client.Send(Serialize(serverReponse)); } }
public void SendToServer(string filePath) { try { if (filePath != String.Empty) { ServerReponse serverReponse = new ServerReponse(); serverReponse.Type = ServerResponseType.SendFile; serverReponse.DataResponse = GetFilePath(filePath); client.Send(Serialize(serverReponse)); MessageBox.Show("Nộp bài thành công"); } } catch (Exception ex) { throw ex; } }
public void Receive(object socket) { var client = socket as Socket; try { while (true) { byte[] data = new byte[1024 * 5000]; client.Receive(data); ServerReponse serverReponse = new ServerReponse(); serverReponse = (ServerReponse)Deserialize(data); switch (serverReponse.Type) { case ServerResponseType.SendFile: byte[] receiveBylength = (byte[])serverReponse.DataResponse; SaveFile(receiveBylength, receiveBylength.Length); break; case ServerResponseType.SendAcceptUser: string ipUser = client.RemoteEndPoint.ToString().Split(':')[0]; var mssv = (string)serverReponse.DataResponse; Updates(mssv); break; default: break; } } } catch (Exception er) { //throw er; Close(); } }
public void Receive() { try { while (true) { byte[] data = new byte[1024 * 5000]; client.Receive(data); ServerReponse serverReponse = new ServerReponse(); serverReponse = (ServerReponse)Deserialize(data); switch (serverReponse.Type) { case ServerResponseType.SendFile: byte[] receiveBylength = (byte[])serverReponse.DataResponse; string nameLink = SaveFile(receiveBylength, receiveBylength.Length); SetText(nameLink); break; case ServerResponseType.BeginExam: object timeExam = serverReponse.DataResponse; int minute = int.Parse(timeExam.ToString()); SetTime(timeExam, minute); /* lblThoiGian.Text = timeExam.ToString() + " Phút"; * int minute = Int32.Parse(timeExam.ToString()); * counter = minute * 60; * countdown.Enabled = true;*/ break; case ServerResponseType.SendStudent: var userList = (List <Students>)serverReponse.DataResponse; SetData(userList); break; case ServerResponseType.sendDe: var subject = (string)serverReponse.DataResponse; SetSubject(subject); break; case ServerResponseType.senMessage: var message = (string)serverReponse.DataResponse; MessageBox.Show(message, "Tin nhắn từ giáo viên"); break; //case ServerResponseType.sendfileexcel: // var userListexcel = (List<studentFromExcels>)serverReponse.DataResponse; // break; case ServerResponseType.SendActiveControl: this.Invoke(new Action(() => { cmdChapNhan.Enabled = true; checkNopBaiThi(); cbDSThi.Enabled = true; // cmdKetNoi.Enabled = true; })); break; case ServerResponseType.CloseClient: this.Invoke(new Action(() => { LogOutuser(); })); break; default: break; } } } catch (Exception er) { // throw er; Close(); } }