Started a new branch for the networking side of story 29, 30
-added a basic tcp server and client #story[778, 782]
This commit is contained in:
@@ -29,54 +29,4 @@ public class App extends Application {
|
||||
stage.show();
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Loads and sets up the GUI elements
|
||||
// *
|
||||
// * @param primaryStage Base for all scenes
|
||||
// * @throws Exception Error in initialising programme
|
||||
// */
|
||||
// @Override
|
||||
// public void start(Stage primaryStage) throws Exception {
|
||||
// this.primaryStage = primaryStage;
|
||||
// primaryStage.minHeightProperty().setValue(600);
|
||||
// primaryStage.minWidthProperty().setValue(780);
|
||||
// //load the first container
|
||||
// try {
|
||||
// FXMLLoader loader = new FXMLLoader();
|
||||
// InputStream in = getClass().getClassLoader().getResourceAsStream("scenes/main.fxml");
|
||||
// mainContainer = (BorderPane) loader.load(in);
|
||||
// mainScene = new Scene(mainContainer, 1200, 800);
|
||||
// primaryStage.setScene(mainScene);
|
||||
// primaryStage.sizeToScene();
|
||||
// MainController mainController = (MainController) loader.getController();
|
||||
// mainController.setParent(this);
|
||||
// in.close();
|
||||
// //add the center
|
||||
// loadPane("race.fxml");
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// primaryStage.show();
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * Loads panes for use in the GUI
|
||||
// *
|
||||
// * @param fxmlName name of resource fxml file
|
||||
// * @throws Exception critical error in loading file
|
||||
// */
|
||||
// public void loadPane(String fxmlName) throws Exception {
|
||||
// FXMLLoader loader = new FXMLLoader();
|
||||
// InputStream in = getClass().getClassLoader().getResourceAsStream("scenes/" + fxmlName);
|
||||
// Parent page;
|
||||
// try {
|
||||
// page = (Parent) loader.load(in);
|
||||
// } finally {
|
||||
// in.close();
|
||||
// }
|
||||
// mainContainer.getChildren().remove(mainContainer.getCenter());
|
||||
// mainContainer.setCenter(page);
|
||||
// Controller controller = (Controller) loader.getController();
|
||||
// controller.setParent(this);
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package seng302;
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
|
||||
/**
|
||||
* TCP client to recive information from AC35 data source
|
||||
*/
|
||||
public class TCPClient
|
||||
{
|
||||
public static void startClient() throws Exception
|
||||
{
|
||||
String sentence;
|
||||
String modifiedSentence;
|
||||
BufferedReader inFromUser = new BufferedReader( new InputStreamReader(System.in));
|
||||
Socket clientSocket = new Socket("localhost", 6789);
|
||||
DataOutputStream outToServer = new DataOutputStream(clientSocket.getOutputStream());
|
||||
BufferedReader inFromServer = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
|
||||
sentence = inFromUser.readLine();
|
||||
outToServer.writeBytes(sentence + '\n');
|
||||
modifiedSentence = inFromServer.readLine();
|
||||
System.out.println("FROM SERVER: " + modifiedSentence);
|
||||
clientSocket.close();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package seng302;
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
|
||||
/**
|
||||
* TCP server to act as the mock AC35 streaming interface
|
||||
*/
|
||||
public class TCPServer
|
||||
{
|
||||
public static void startServer() throws Exception
|
||||
{
|
||||
String clientSentence;
|
||||
String capitalizedSentence;
|
||||
//socket port 4942 as 4940 is ac35 live port and 4941 is ac35 test port
|
||||
ServerSocket welcomeSocket = new ServerSocket(4942);
|
||||
|
||||
while(true)
|
||||
{
|
||||
Socket connectionSocket = welcomeSocket.accept();
|
||||
BufferedReader inFromClient =
|
||||
new BufferedReader(new InputStreamReader(connectionSocket.getInputStream()));
|
||||
DataOutputStream outToClient = new DataOutputStream(connectionSocket.getOutputStream());
|
||||
clientSentence = inFromClient.readLine();
|
||||
System.out.println("Received: " + clientSentence);
|
||||
capitalizedSentence = clientSentence.toUpperCase() + '\n';
|
||||
outToClient.writeBytes(capitalizedSentence);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user