Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.io.*;
- import java.net.*;
- public class Client
- {
- public static void main(String[] args) throws IOException
- {
- Socket socket = null;
- PrintWriter out = null;
- BufferedReader in = null;
- try
- {
- //aby utworzyć Socket trzeba podać adres i port serwera
- socket = new Socket("szymon.ia.agh.edu.pl", 3000);
- //PrintWriter wypisuje sformatowaną reprezentację obiektów
- out = new PrintWriter(socket.getOutputStream(), true);
- //BufferedReader czyta tekst ze strumienia wejściowego, używa buforowania (czyta po kawałku)
- in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
- }
- catch(UnknownHostException e)
- {
- System.err.println("Don't know about host: szymon.ia.agh.edu.pl");
- System.exit(1);
- }
- catch(IOException e)
- {
- System.err.println("Couldn't get I/O for the connection to: szymon.ia.agh.edu.pl.");
- System.exit(1);
- }
- BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
- String userInput;
- System.out.println("Type: ");
- while((userInput = stdIn.readLine()) != null) //dopóki nie ma końca znaku
- {
- out.println(userInput); //pisanie do gniazda
- System.out.println(in.readLine()); //czytanie z gniazda
- }
- out.close();
- in.close();
- stdIn.close();
- socket.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement