Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package javatcp;
- import java.net.*;
- import java.io.*;
- public class JavaClient {
- /**
- * @param args porta da utilizzare (default 6666)
- */
- public static void main(String[] args) throws Exception{
- int port=6666;
- if (args.length == 1) {
- try {port = Integer.parseInt(args[0]);}
- catch (Exception e) { System.out.println("Errore nel parametro, uso il default"); }
- }
- // Apre una connessione TCP (port di default 6666)
- Socket socket = new Socket("localhost",port);
- // Apre gli stream
- DataOutputStream bufferOutput = new DataOutputStream(socket.getOutputStream());
- BufferedReader input = new BufferedReader (new InputStreamReader(System.in));
- while (true) {
- // Legge Dal Server
- String messaggio = input.readLine();
- bufferOutput.writeBytes(messaggio + '\n');
- if (messaggio.toUpperCase().trim().equals("CIAO"))
- break;
- }
- socket.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement