Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package Client;
- import java.io.*;
- import java.net.Socket;
- import java.net.UnknownHostException;
- public class Client {
- public static void main(String[] args) {
- try {
- String toSend = "Czesc ucze sie javy";
- Socket socket = new Socket("localhost", 5555);
- final InputStream inputStream = socket.getInputStream();
- final OutputStream outputStream = socket.getOutputStream();
- final BufferedReader readFromSocket = new BufferedReader(new InputStreamReader(inputStream));
- final DataOutputStream writeToSocket = new DataOutputStream(outputStream);
- writeToSocket.writeBytes("CZESC\n");
- String s = null;
- while ((s = readFromSocket.readLine()) != null) {
- System.out.println(s);
- if (s.equals("Hi")) {
- writeToSocket.writeBytes("SEND\n");
- }
- if (s.equals("OK")) {
- writeToSocket.writeBytes("Thanks!\n");
- }
- }
- readFromSocket.close();
- writeToSocket.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement