Changed directory structure
1 parent 3f8ea6f commit 6be513c0c3ff98934558e2357f8e7d5fa35fded1
@Andreas Jaggi Andreas Jaggi authored on 12 Jun 2006
x-way committed on 12 Jun 2006
Showing 32 changed files
View
82
build.xml 100644 → 0
<project name="nonet" default="dist" basedir=".">
<description>
simple build file
</description>
 
<!-- set global properties -->
<property name="src" location="src"/>
<property name="build" location="build"/>
<property name="dist" location="dist"/>
<property name="lib" location="lib"/>
 
<target name="init">
<!-- Create the time stamp -->
<tstamp/>
<!-- Create the build directory structure used by compile -->
<mkdir dir="${build}"/>
</target>
 
<target name="compile" depends="init" description="compile the source">
<!-- Compile the java code from ${src} into ${build} -->
<javac srcdir="${src}" destdir="${build}">
<classpath>
<pathelement path="${build}"/>
</classpath>
</javac>
</target>
 
<target name="dist" depends="compile" description="generate the distribution">
<!-- Create the distribution directory -->
<mkdir dir="${dist}/lib"/>
 
<!-- 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="prog" depends="compile" description="run server">
<java classname="ch.epfl.lca.sc250.PlayerProgram" fork="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">
<classpath>
<pathelement path="${build}"/>
</classpath>
</java>
</target>
 
<target name="server" depends="compile" description="run server">
<java classname="ch.epfl.lca.sc250.UDPServer" fork="true" spawn="true">
<classpath>
<pathelement path="${build}"/>
</classpath>
</java>
</target>
 
<target name="clean" description="clean up">
<!-- Delete the ${build} and ${dist} directory trees -->
<delete dir="${build}"/>
<delete dir="${dist}"/>
</target>
</project>
View
32
src/ch/epfl/lca/sc250/PlayerProgram.java 100644 → 0
package ch.epfl.lca.sc250;
 
import ch.epfl.lca.sc250.gui.finalgui.*;
 
 
public class PlayerProgram {
TCPClient tcpC;
UDPServer udpS;
ServentServer svS;
ServentClient svC;
CnFrameMain gui;
 
public PlayerProgram ( ) {
gui = new CnFrameMain("fdasdf-sdafsadfä-fsad-fsdaf--");
tcpC = new TCPClient("in3sun23.epfl.ch", 13370, "x-way", gui);
udpS = new UDPServer(gui);
svC = new ServentClient(gui);
svS = new ServentServer(gui);
}
 
public void launch ( ) {
tcpC.start();
udpS.start();
svS.start();
}
 
public static void main ( String[] args ) {
PlayerProgram p = new PlayerProgram();
p.launch();
}
}
View
80
src/ch/epfl/lca/sc250/ServentClient.java 100644 → 0
package ch.epfl.lca.sc250;
 
import ch.epfl.lca.sc250.gui.finalgui.*;
 
import java.net.*;
import java.io.*;
 
/**
* @author Christophe Trefois
*/
public class ServentClient implements ITCPSender {
 
/**
* Instance of the GUI
*/
CnFrameMain myGui;
 
private Socket sock;
private int targetport = 13371;
private BufferedReader inReader;
private DataOutputStream outStream;
 
 
/**
* Constructor of the Client part of the Servent for
*
* @param windowTitle The title of the GUI
*/
public ServentClient(CnFrameMain gui) {
myGui = gui;
// Give the GUI an instance of the ServentClient
myGui.setTcpSender(this);
}
 
/**
* Creates a new instance of ServentClient
* @param args
*/
public static void main(String[] args) {
new ServentClient(new CnFrameMain("abc"));
}
 
/**
* This method should open a TCP Socket and send the offer to the other player
*/
public void sendMessage(String ipAddress, String moneyAmount, String letterPosition) {
// Open Communication to other Player and wait for a result
// When result is recevied, display it in GUI
 
System.out.println("Message sent to " + ipAddress + " : " + moneyAmount + ", " + letterPosition);
// Opening Socket, Sending Request, Fetching answer
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
75
src/ch/epfl/lca/sc250/ServentServer.java 100644 → 0
package ch.epfl.lca.sc250;
 
import javax.swing.JOptionPane;
 
import java.io.*;
import java.net.*;
 
import ch.epfl.lca.sc250.gui.finalgui.*;
 
/**
* @author Christophe Trefois
*
*/
public class ServentServer extends Thread {
 
private CnFrameMain gui;
 
public static void main(String[] args) {
ServentServer s = new ServentServer(new CnFrameMain("abc"));
s.loop();
}
 
public ServentServer ( CnFrameMain gui ) {
this.gui = gui;
}
 
public void run ( ) {
this.loop();
}
 
public void loop ( ) {
// Open a Socket and listen on incoming offer requests.
//
try {
boolean result;
String message;
ServerSocket knockSock;
Socket sock;
int targetport = 13371;
BufferedReader inReader;
DataOutputStream outStream;
knockSock = new ServerSocket(targetport);
 
while ( true ) {
 
sock = knockSock.accept();
 
outStream = new DataOutputStream(sock.getOutputStream());
inReader = new BufferedReader(new InputStreamReader(sock.getInputStream()));
 
message = inReader.readLine();
 
String[] parsed = message.split(", ");
 
// We suppose we got and parsed an offer, we then want the pop-up to display
result = gui.getOfferResult(sock.getInetAddress().toString(), parsed[0], parsed[1]);
 
if(result) {
System.out.println("Yes");
outStream.writeBytes("Yes\n");
} else {
System.out.println("No");
outStream.writeBytes("No\n");
}
 
sock.close();
}
} catch ( IOException e ) {
System.out.println("IO-Error");
e.printStackTrace();
}
}
}
View
src/ch/epfl/lca/sc250/TCPClient.java 100644 → 0
View
src/ch/epfl/lca/sc250/UDPServer.java 100644 → 0
View
src/ch/epfl/lca/sc250/gui/CellRenderer.java 100644 → 0
View
src/ch/epfl/lca/sc250/gui/CnFrame.java 100644 → 0
View
src/ch/epfl/lca/sc250/gui/CnFrameP2P.java 100644 → 0
View
src/ch/epfl/lca/sc250/gui/CnFrameTCP.java 100644 → 0
View
src/ch/epfl/lca/sc250/gui/CnFrameUDP.java 100644 → 0
View
src/ch/epfl/lca/sc250/gui/ITCPSender.java 100644 → 0
View
src/ch/epfl/lca/sc250/gui/finalgui/CellRenderer.java 100644 → 0
View
src/ch/epfl/lca/sc250/gui/finalgui/CnFrameMain.java 100644 → 0
View
src/ch/epfl/lca/sc250/gui/finalgui/ITCPSender.java 100644 → 0
View
src/testingPackage/GuiNewFrameTest.java 100644 → 0
View
tp6-8/build.xml 0 → 100644
View
tp6-8/src/ch/epfl/lca/sc250/PlayerProgram.java 0 → 100644
View
tp6-8/src/ch/epfl/lca/sc250/ServentClient.java 0 → 100644
View
tp6-8/src/ch/epfl/lca/sc250/ServentServer.java 0 → 100644
View
tp6-8/src/ch/epfl/lca/sc250/TCPClient.java 0 → 100644
View
tp6-8/src/ch/epfl/lca/sc250/UDPServer.java 0 → 100644
View
tp6-8/src/ch/epfl/lca/sc250/gui/CellRenderer.java 0 → 100644
View
tp6-8/src/ch/epfl/lca/sc250/gui/CnFrame.java 0 → 100644
View
tp6-8/src/ch/epfl/lca/sc250/gui/CnFrameP2P.java 0 → 100644
View
tp6-8/src/ch/epfl/lca/sc250/gui/CnFrameTCP.java 0 → 100644
View
tp6-8/src/ch/epfl/lca/sc250/gui/CnFrameUDP.java 0 → 100644
View
tp6-8/src/ch/epfl/lca/sc250/gui/ITCPSender.java 0 → 100644
View
tp6-8/src/ch/epfl/lca/sc250/gui/finalgui/CellRenderer.java 0 → 100644
View
tp6-8/src/ch/epfl/lca/sc250/gui/finalgui/CnFrameMain.java 0 → 100644
View
tp6-8/src/ch/epfl/lca/sc250/gui/finalgui/ITCPSender.java 0 → 100644
View
tp6-8/src/testingPackage/GuiNewFrameTest.java 0 → 100644