private void ClientStartThread() { try { do { networkStream = client.GetStream(); bytes = new byte[client.ReceiveBufferSize]; networkStream.Read(bytes, 0, client.ReceiveBufferSize); receivedData = Encoding.ASCII.GetString(bytes); if (receivedData.Replace("\0", "") == "Cerrando conexion...") { clientForm.SetMessage(receivedData); //servidor se esta ejecutando clientForm.Disconnect(); } else { path = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); //carpeta del usuario File.WriteAllBytes(path + "\\Downloads\\" + fileName + ".txt", bytes); //Guardado archivo clientForm.SetMessage("Archivo descargado correctamente..."); } } while (client.Connected); } catch (IOException) { clientForm.Disconnect(); clientForm.SetMessage("Cliente desconectado..."); } catch (InvalidOperationException) { clientForm.Disconnect(); clientForm.SetMessage("Servidor desconectado..."); } }
private void ClientStartThread() { try { do { networkStream = client.GetStream(); bytes = new byte[client.ReceiveBufferSize]; networkStream.Read(bytes, 0, client.ReceiveBufferSize); receivedData = Encoding.ASCII.GetString(bytes); if (receivedData.Replace("\0", "") == "Closing connection...") { clientForm.SetMessage(receivedData); //servidor esta executando clientForm.Disconnect(); } else { path = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile); //pasta do usuário File.WriteAllBytes(path + "\\Downloads\\" + fileName + ".txt", bytes); //salva arquivo clientForm.SetMessage("File downloaded successfully..."); } } while (client.Connected); } catch (IOException) { clientForm.Disconnect(); clientForm.SetMessage("Client disconnected..."); } catch (InvalidOperationException) { clientForm.Disconnect(); clientForm.SetMessage("Server is offline..."); } }
private void ClientStartThread() { try { do { networkStream = client.GetStream(); if (networkStream.CanRead) { byte[] bytes = new byte[client.ReceiveBufferSize]; networkStream.Read(bytes, 0, Convert.ToInt32(client.ReceiveBufferSize)); string returnData = Encoding.ASCII.GetString(bytes); if (returnData.Replace("\0", "") == "Closing connection...") { clientForm.SetMessage(returnData); clientForm.Disconnect(); } } else { clientForm.SetMessage("Error"); clientForm.Disconnect(); } } while (client.Connected); } catch (IOException) { clientForm.SetMessage("Client disconnected..."); } catch (InvalidOperationException) { clientForm.SetMessage("Server is offline..."); clientForm.Disconnect(); } }