Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package clientelisa;
- import java.io.DataInputStream;
- import java.io.DataOutputStream;
- import java.io.IOException;
- import java.net.ServerSocket;
- import java.net.Socket;
- import java.util.logging.Level;
- import java.util.logging.Logger;
- public class ClientElisa {
- Socket socket;
- boolean stop = true;
- ClientElisa() {
- try {
- socket = new Socket("127.0.0.1", 33061);
- DataOutputStream tmpOut = new DataOutputStream(socket.getOutputStream());
- tmpOut.writeUTF("10 + 10");
- tmpOut.flush();
- } catch (IOException ex) {
- Logger.getLogger(ClientElisa.class.getName()).log(Level.SEVERE, null, ex);
- }
- try {
- ServerSocket ss = new ServerSocket(1000);
- while (stop) {
- try {
- socket = ss.accept();
- // PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
- // out.println("ciao");
- DataInputStream in = new DataInputStream(socket.getInputStream());
- String str = in.readUTF().toString();
- if (!str.equals("")) {
- System.out.println(str);
- stop = false;
- }
- socket.close();
- } catch (IOException ex) {
- Logger.getLogger(ClientElisa.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- } catch (IOException ex) {
- Logger.getLogger(ClientElisa.class.getName()).log(Level.SEVERE, null, ex);
- }
- }
- public static void main(String[] args) {
- ClientElisa ce = new ClientElisa();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment