Advertisement
Guest User

Untitled

a guest
Jan 21st, 2019
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. import java.net.*;
  2. import java.io.*;
  3.  
  4. public class Main {
  5.  
  6. public Main() {
  7. }
  8.  
  9. public static void main(String[] args) {
  10. ServerSocket gniazdoSerwera = null;
  11. Socket gniazdo = null;
  12. BufferedReader odczyt = null;
  13. DataOutputStream strWy = null;
  14. String linia;
  15.  
  16. try {
  17. gniazdoSerwera = new ServerSocket(6000);
  18. } catch (Exception e) {
  19. System.out.println("Błąd - gniazdo serwera");
  20. System.exit(-1);
  21. }
  22.  
  23. System.out.println("Serwer uruchomiony");
  24.  
  25. try {
  26. gniazdo = gniazdoSerwera.accept();
  27. } catch (Exception e) {
  28. System.out.println("Błąd - połączenie");
  29. System.exit(-1);
  30. }
  31.  
  32. try {
  33. InputStream strWeGniazda = gniazdo.getInputStream();
  34. odczyt = new BufferedReader(new InputStreamReader(strWeGniazda));
  35.  
  36. OutputStream strWyGniazda = gniazdo.getOutputStream();
  37. strWy = new DataOutputStream(strWyGniazda);
  38. } catch (IOException e) {
  39. System.out.println("Błąd - strumienie");
  40. System.exit(-1);
  41. }
  42.  
  43. try {
  44. linia = odczyt.readLine();
  45.  
  46. if (linia.equals("quit")) {
  47. System.out.println("Koniec pracy serwera");
  48. gniazdoSerwera.close();
  49. System.exit(0);
  50. }
  51.  
  52. System.out.println("Otrzymane: " + linia);
  53. String album= "87401";
  54. int m = linia.charAt(3);
  55. int mm = linia.charAt(4);
  56. char k;
  57. int x=0;
  58. for (int i = 0; i < album.length(); i++) {
  59. k=album.charAt(i);
  60. if (k==m) {
  61. x++;
  62. }
  63. }
  64.  
  65. for (int i = 0; i < album.length(); i++) {
  66. k=album.charAt(i);
  67. if (k==mm) {
  68. x++;
  69. }
  70. }
  71.  
  72. if(x>0) {
  73. linia = "cyfra zawiera sie w indeksie " ;
  74. }
  75. strWy.writeBytes(linia + "\n");
  76.  
  77. //Opróżnienie strumienia wyjściowego:
  78. strWy.flush();
  79. } catch (IOException e) {
  80. System.out.println("Błąd - operacje we/wy");
  81. System.exit(-1);
  82. }
  83.  
  84. }
  85.  
  86. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement