import java.net.*; import java.io.*; public class JChatClient { private DataOutputStream os; private BufferedReader is; private Socket socket; public void start()throws IOException { //Connessione della Socket con il Server socket = new Socket("10.17.7.147", 7777); //Stream di byte da passare al Socket os = new DataOutputStream(socket.getOutputStream()); is = new BufferedReader(new InputStreamReader(socket.getInputStream())); } public void sendMessage(String strMessage)throws IOException { os.writeBytes(strMessage + '\n'); } public String receiveMessage() throws IOException { return is.readLine(); } public void close() throws IOException { System.out.println("Chiusura client"); os.close(); is.close(); socket.close(); } } La classe JchatServerRunner viene utilizzata semplicemente per mandare in esecuzione il server: public class JchatServerRunner { public static void main(String[] args) { JChatServer serverChat = new JChatServer(); try { serverChat.start(); } catch (Exception ex) { ex.printStackTrace(); } } }