private void openFromFile_Click(object sender, EventArgs e) { String Location = String.Empty; try { // Kiểm tra xem có bộ câu hỏi nào đang mở hay không if (_groupquestion != null) { DialogResult dialogResult = MessageBox.Show("Bạn có muốn lưu bạn hiện tại không?", "Lưu", MessageBoxButtons.YesNoCancel); if (dialogResult == DialogResult.Yes) { _groupquestion.SaveToFile(tbQuestionGroupName.Text, tbAddress.Text); } if (dialogResult == DialogResult.Cancel) { return; } } #if DEBUG Location = "D:/Bộ câu hỏi 1.json"; #else clearValue(); OpenFileDialog frm = new OpenFileDialog(); frm.InitializeLifetimeService(); frm.Filter = "Bộ đề (*.json)|*.json"; frm.Title = "Browse Config file"; DialogResult ret = STAShowDialog(frm); if (ret == DialogResult.OK) { Location = frm.FileName; } #endif if (Location != "") { _groupquestion = new MyGroupQuestion(); _groupquestion.LoadFromFile(Location); updateListQuestions(); tbAddress.Text = Location; _groupquestion.Address = Location; tbQuestionGroupName.Text = _groupquestion.Name; tbQuestion.Focus(); } } catch (Exception ex) { MyLogSystem.Log(ex.ToString()); } }
public void task() { while ((isRunning)) { try { TcpClient clientSocket = default(TcpClient); clientSocket = myserverSocket.AcceptTcpClient(); _clmanage.addNewClient(clientSocket); } catch (Exception ex) { MyLogSystem.Log(ex.ToString()); } } }
/// <summary> /// return true if connect successful. Return fail when cant connect /// </summary> /// <returns></returns> public bool startConnection(string ipServer) { try { if (_socket.Connected) { return(true); } _socket.Connect(ipServer, 8888); return(true); } catch (Exception ex) { MyLogSystem.Log(ex.ToString()); return(false); } return(false); }
private void listenFromServer() { while (isRunning) { try { NetworkStream networkStream = clientSocket.GetStream(); byte[] bytesFrom = new byte[10025]; networkStream.Read(bytesFrom, 0, (int)clientSocket.ReceiveBufferSize); string dataFromClient = MyDecodeUnicode.DecodeFromUtf8(Encoding.Unicode.GetString(bytesFrom)); processRequest(dataFromClient); } catch (Exception ex) { MyLogSystem.Log(ex.ToString()); } } }