Skip to content

Commit

Permalink
Merge pull request #2 from spff/master
Browse files Browse the repository at this point in the history
hi
  • Loading branch information
spff committed Jun 22, 2015
2 parents 6c77dfc + 9201a3f commit 2ea3714
Show file tree
Hide file tree
Showing 8 changed files with 270 additions and 106 deletions.
97 changes: 0 additions & 97 deletions TestClientcpp/testclient.cpp

This file was deleted.

107 changes: 107 additions & 0 deletions client/main/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
package main;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class Main extends Application {

private static Main instance;

Socket socket = null;
PrintWriter out = null;
BufferedReader in = null;
InetAddress host = null;

String usrname, resolution;

public Main() {
instance = this;
}

// static method to get instance of view
public static Main getInstance() {
return instance;
}

@Override
public void start(Stage primaryStage) {
try {

Process p = Runtime.getRuntime().exec("whoami");
BufferedReader bri = new BufferedReader(new InputStreamReader(
p.getInputStream()));
usrname = bri.readLine();
System.out.println(usrname);
bri.close();


primaryStage.setTitle("Conference client");
Scene scene = new Scene(FXMLLoader.load(getClass().getResource(
"../view/mainview.fxml")));
primaryStage.setScene(scene);
primaryStage.show();

} catch (Exception e) {
e.printStackTrace();
}
}

public static void main(String[] args) {
launch(args);
}

public void connect(String IP, String port) {


System.out.println("Connect");
try {
System.out.println(IP + " " + port);

socket = new Socket(IP, Integer.parseInt(port));
out = new PrintWriter(socket.getOutputStream(), true);
in = new BufferedReader(new InputStreamReader(
socket.getInputStream()));

out.write(usrname);

//resolution = in.readLine();
//THE PROGRAM BLOCK IF READ OR READLINE, NOT JUST READLINE...FXCK

//System.out.println(resolution);


} catch (UnknownHostException e) {
System.err.println("Cannot find the host: " + host.getHostName());
System.exit(1);
} catch (IOException e) {
System.err.println("Couldn't read/write from the connection: "
+ e.getMessage());
System.exit(1);
}

}

public void disconnect() throws IOException {
System.out.println("Disconnect");

socket.close();
out.close();

}

public void sendSignal(String signal) {
out.write(signal);
System.out.println(signal);
}

}
79 changes: 79 additions & 0 deletions client/view/Controller.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package view;

import java.io.IOException;
import java.net.URL;
import java.util.ResourceBundle;

import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.Button;
import javafx.scene.control.Labeled;
import javafx.scene.control.TextField;
import javafx.scene.input.KeyEvent;
import javafx.scene.input.MouseEvent;
import main.Main;

public class Controller implements Initializable {

@FXML
Labeled label1, label2;
@FXML
Button button1;
@FXML
TextField IP, port;

boolean cnt = true;

@Override
public void initialize(URL location, ResourceBundle resources) {

System.out.println("View is now loaded!");

}

private static Controller instance;

public Controller() {
instance = this;
}

public void button1Pressod() throws IOException {

if (cnt) {
button1.setText("disconnect");
Main.getInstance().connect(IP.getText(), port.getText());
IP.setDisable(true);
port.setDisable(true);

} else {
button1.setText(" connect ");
Main.getInstance().disconnect();
IP.setDisable(false);
port.setDisable(false);

}
cnt = !cnt;

}

public void mouseHandler(MouseEvent mouseEvent) {

label1.setText(mouseEvent.getEventType() + " " + mouseEvent.getButton()
+ " " + "(X,Y)=(" + mouseEvent.getX() + "," + mouseEvent.getY()
+ ") ");
if (!cnt)
Main.getInstance().sendSignal(
mouseEvent.getEventType() + " " + mouseEvent.getButton()
+ " " + "(X,Y)=(" + mouseEvent.getX() + ","
+ mouseEvent.getY() + ") ");
}

public void keyboardHandler(KeyEvent keyEvent) {

label2.setText(keyEvent.getEventType() + " " + keyEvent.getText());
if (!cnt)
Main.getInstance().sendSignal(
keyEvent.getEventType() + " " + keyEvent.getText());
}

}
34 changes: 34 additions & 0 deletions client/view/mainview.fxml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?xml version="1.0" encoding="UTF-8"?>

<?import javafx.scene.control.*?>
<?import java.lang.*?>
<?import javafx.scene.layout.*?>
<?import javafx.scene.layout.TilePane?>

<AnchorPane focusTraversable="true" maxHeight="-Infinity" maxWidth="-Infinity" minHeight="-Infinity" minWidth="-Infinity" onContextMenuRequested="#mouseHandler" onInputMethodTextChanged="#keyboardHandler" onKeyPressed="#keyboardHandler" onKeyReleased="#keyboardHandler" onKeyTyped="#keyboardHandler" onMouseClicked="#mouseHandler" onMouseDragged="#mouseHandler" onMouseMoved="#mouseHandler" onMousePressed="#mouseHandler" onMouseReleased="#mouseHandler" onScroll="#mouseHandler" onScrollFinished="#mouseHandler" onScrollStarted="#mouseHandler" prefHeight="720.0" prefWidth="1280.0" xmlns="http://javafx.com/javafx/8.0.40" xmlns:fx="http://javafx.com/fxml/1" fx:controller="view.Controller">
<children>
<MenuBar layoutX="-14.0" prefHeight="29.0" prefWidth="616.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
<menus>
<Menu mnemonicParsing="false" text="File">
<items>
<MenuItem mnemonicParsing="false" text="Close" />
</items>
</Menu>
<Menu mnemonicParsing="false" text="Help">
<items>
<MenuItem mnemonicParsing="false" text="About" />
</items>
</Menu>
</menus>
</MenuBar>
<ToolBar layoutY="29.0" prefHeight="40.0" prefWidth="342.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="29.0">
<items>
<TextField fx:id="IP" prefHeight="26.0" prefWidth="132.0" promptText="IP" text="127.0.0.1" />
<TextField fx:id="port" prefHeight="26.0" prefWidth="63.0" promptText="port" text="3412" />
<Button fx:id="button1" mnemonicParsing="false" onMousePressed="#button1Pressod" text=" connect " />
<Label fx:id="label1" prefHeight="22.0" prefWidth="896.0" text="Debug Label" />
</items>
</ToolBar>
<Label fx:id="label2" layoutX="251.0" layoutY="69.0" prefHeight="40.0" prefWidth="729.0" />
</children>
</AnchorPane>
2 changes: 1 addition & 1 deletion comment
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
TODO

Client
Client:read not blocking from server
Server:Action, xinput
32 changes: 32 additions & 0 deletions javaclienttest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package javaclienttest;

import java.io.*;
import java.net.*;


public class javaclienttest {
public static void main(String[] args) throws IOException {



String hostName = "127.0.0.1";
int portNumber = Integer.parseInt("3412");
Socket firstSocket = new Socket(hostName, portNumber);
PrintWriter out = new PrintWriter(firstSocket.getOutputStream(), true);
BufferedReader in = new BufferedReader(new InputStreamReader(firstSocket.getInputStream()));
BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
String userInput;

out.println("spff");
System.out.println("received: " + in.readLine());

while ((userInput = stdIn.readLine()) != null)
{
out.println(userInput);
}
in.close();
stdIn.close();
firstSocket.close();

}
}
Loading

0 comments on commit 2ea3714

Please sign in to comment.