Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.net.*;
- import java.io.*;
- public class Main {
- public Main() {
- }
- public static void main(String[] args) {
- ServerSocket gniazdoSerwera = null;
- Socket gniazdo = null;
- BufferedReader odczyt = null;
- DataOutputStream strWy = null;
- String linia;
- try {
- gniazdoSerwera = new ServerSocket(6000);
- } catch (Exception e) {
- System.out.println("Błąd - gniazdo serwera");
- System.exit(-1);
- }
- System.out.println("Serwer uruchomiony");
- try {
- gniazdo = gniazdoSerwera.accept();
- } catch (Exception e) {
- System.out.println("Błąd - połączenie");
- System.exit(-1);
- }
- try {
- InputStream strWeGniazda = gniazdo.getInputStream();
- odczyt = new BufferedReader(new InputStreamReader(strWeGniazda));
- OutputStream strWyGniazda = gniazdo.getOutputStream();
- strWy = new DataOutputStream(strWyGniazda);
- } catch (IOException e) {
- System.out.println("Błąd - strumienie");
- System.exit(-1);
- }
- try {
- linia = odczyt.readLine();
- if (linia.equals("quit")) {
- System.out.println("Koniec pracy serwera");
- gniazdoSerwera.close();
- System.exit(0);
- }
- System.out.println("Otrzymane: " + linia);
- String album= "87401";
- int m = linia.charAt(3);
- int mm = linia.charAt(4);
- char k;
- int x=0;
- for (int i = 0; i < album.length(); i++) {
- k=album.charAt(i);
- if (k==m) {
- x++;
- }
- }
- for (int i = 0; i < album.length(); i++) {
- k=album.charAt(i);
- if (k==mm) {
- x++;
- }
- }
- if(x>0) {
- linia = "cyfra zawiera sie w indeksie " ;
- }
- strWy.writeBytes(linia + "\n");
- //Opróżnienie strumienia wyjściowego:
- strWy.flush();
- } catch (IOException e) {
- System.out.println("Błąd - operacje we/wy");
- System.exit(-1);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement