| | package ch.epfl.lca.sc250; |
---|
| | |
---|
| | import ch.epfl.lca.sc250.gui.CnFrameP2P; |
---|
| | import ch.epfl.lca.sc250.gui.ITCPSender; |
---|
| | |
---|
| | import java.net.*; |
---|
| | import java.io.*; |
---|
| | |
---|
| | /** |
---|
| | * @author Christophe Trefois |
---|
| | */ |
---|
| |
---|
| | /** |
---|
| | * Instance of the GUI |
---|
| | */ |
---|
| | CnFrameP2P myGui; |
---|
| | |
---|
| | private Socket sock; |
---|
| | private int targetport = 13371; |
---|
| | private BufferedReader inReader; |
---|
| | private DataOutputStream outStream; |
---|
| | |
---|
| | |
---|
| | /** |
---|
| | * Constructor of the Client part of the Servent for |
---|
| | * |
---|
| |
---|
| | |
---|
| | System.out.println("Message sent to " + ipAddress + " : " + moneyAmount + ", " + letterPosition); |
---|
| | |
---|
| | // Opening Socket, Sending Request, Fetching answer |
---|
| | // Put the answer in String message = theAnswer; |
---|
| | // Call this method to unblock the GUI |
---|
| | |
---|
| | // myGui.receivedMessage(message); |
---|
| | try { |
---|
| | sock = new Socket(ipAddress, targetport); |
---|
| | |
---|
| | outStream = new DataOutputStream(sock.getOutputStream()); |
---|
| | |
---|
| | inReader = new BufferedReader(new InputStreamReader(sock.getInputStream())); |
---|
| | } catch ( UnknownHostException uhe ) { |
---|
| | System.out.println("Unknown host"); |
---|
| | } catch ( IOException ioe ) { |
---|
| | System.out.println("IO-Error"); |
---|
| | } |
---|
| | |
---|
| | try { |
---|
| | outStream.writeBytes(moneyAmount + ", " + letterPosition + "\n"); |
---|
| | |
---|
| | // Put the answer in String message = theAnswer; |
---|
| | // Call this method to unblock the GUI |
---|
| | String response = inReader.readLine(); |
---|
| | |
---|
| | myGui.receivedMessage(response); |
---|
| | } catch ( IOException ioe ) { |
---|
| | System.out.println("IO-Error"); |
---|
| | } |
---|
| | |
---|
| | } |
---|
| | |
---|
| | } |
---|
| | |
---|
| | |