Setup client-server communication infrastructure.

Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
main
Nic0Nic0Nii 4 years ago
parent 727b521a3c
commit 8001abc406
  1. 1
      .gitignore
  2. 31
      src/main/java/sig/App.java
  3. 2
      src/main/java/sig/Client.java
  4. 1
      src/main/java/sig/ClientHandler.java
  5. 8
      src/main/java/sig/Server.java

1
.gitignore vendored

@ -1,3 +1,2 @@
bin
target
target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst

@ -14,6 +14,12 @@ import com.github.kwhat.jnativehook.keyboard.NativeKeyListener;
import javax.swing.JFrame;
public class App implements NativeKeyListener{
public static boolean CLIENT = true; //true for CLIENT. false for SERVER.
public static String SERVER = "projectdivar.com";
public static int PORT = 5950;
public static double FRAMETIME=0;
public static Robot r;
public static JFrame f;
@ -25,8 +31,18 @@ public class App implements NativeKeyListener{
System.out.println("Key Released: " + NativeKeyEvent.getKeyText(e.getKeyCode()));
}
App(boolean client) {
if (!client) {
Server s = new Server();
System.out.println("Starting server on port "+PORT+"...");
s.start(PORT);
} else {
new App();
}
}
App() {
RegisterKeyboardHook();
/*RegisterKeyboardHook();
try {
@ -36,6 +52,13 @@ public class App implements NativeKeyListener{
}
RunInitialAnalysis();
f = new JFrame("FFXIV AI");
*/
Client c = new Client();
System.out.println("Connecting to "+SERVER+" on port "+PORT+".");
c.start(SERVER,PORT);
System.out.println(c.sendMessage("I am in!"));
System.out.println(c.sendMessage("EOF"));
c.stop();
}
private void RegisterKeyboardHook() {
@ -53,7 +76,11 @@ public class App implements NativeKeyListener{
}
public static void main(String[] args) {
App a = new App();
if (!CLIENT) {
new App(CLIENT);
} else {
new App();
}
}
private static void RunInitialAnalysis() {
long startTime = System.nanoTime();

@ -12,8 +12,8 @@ public class Client {
BufferedReader in;
public void start(String ip,int port) {
socket = new Socket();
try {
socket = new Socket(ip,port);
out = new PrintWriter(socket.getOutputStream(),true);
in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
} catch (IOException e) {

@ -22,6 +22,7 @@ public class ClientHandler extends Thread{
while ((line=in.readLine())!=null) {
if (line.equals("EOF")) {
out.println("Goodbye.");
break;
}
out.println(line);
}

@ -16,4 +16,12 @@ public class Server {
e.printStackTrace();
}
}
public void stop() {
try {
socket.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}

Loading…
Cancel
Save