Completed exercice 2 of lab 7
1 parent d4fc0ba commit 45d5f9a6bab58b9494dfc48366d8c91cb19f6bf7
@Andreas Jaggi Andreas Jaggi authored on 4 May 2006
x-way committed on 4 May 2006
Showing 3 changed files
View
16
build.xml
<!-- Put everything in ${build} into the kernelpanic-${DSTAMP}.jar file -->
<jar jarfile="${dist}/lib/kernelpanic-{$DSTAMP}.jar" basedir="${build}"/>
</target>
 
<target name="serventserver" depends="compile" description="run server">
<java classname="ch.epfl.lca.sc250.ServentServer" fork="true" spawn="true">
<classpath>
<pathelement path="${build}"/>
</classpath>
</java>
</target>
 
<target name="serventclient" depends="compile" description="run server">
<java classname="ch.epfl.lca.sc250.ServentClient" fork="true" spawn="true">
<classpath>
<pathelement path="${build}"/>
</classpath>
</java>
</target>
 
<target name="client" depends="compile" description="run server">
<java classname="ch.epfl.lca.sc250.TCPClient" fork="true" spawn="true">
<classpath>
<pathelement path="${build}"/>
View
57
src/ch/epfl/lca/sc250/ServentClient.java
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");
}
 
}
 
}
View
src/ch/epfl/lca/sc250/ServentServer.java