package gotowe.p46_tcp;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Scanner;

public class Serwer2 {

	public static void main(String[] args) {
		try {
			System.out.println("tworzę socket");
			try(ServerSocket serverSocket = new ServerSocket(5556)) {
				while(true) {
				System.out.println("czekam na połączenie");
				try(Socket connectionSocket = serverSocket.accept()) {
					System.out.println("jest klient: " + connectionSocket.getRemoteSocketAddress());
					
					try(InputStream in = connectionSocket.getInputStream();
						OutputStream out = connectionSocket.getOutputStream()) {
						int bajt;
						do {
							bajt = in.read();
							System.out.println(bajt);
						} while(bajt != -1);
					}
				}
				}
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
