-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4"> | ||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8"> | ||
<output url="file://$MODULE_DIR$/target/classes" /> | ||
<output-test url="file://$MODULE_DIR$/target/test-classes" /> | ||
<content url="file://$MODULE_DIR$"> | ||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" /> | ||
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" /> | ||
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" /> | ||
<excludeFolder url="file://$MODULE_DIR$/target" /> | ||
</content> | ||
<orderEntry type="jdk" jdkName="10" jdkType="JavaSDK" /> | ||
<orderEntry type="sourceFolder" forTests="false" /> | ||
<orderEntry type="library" name="core" level="project" /> | ||
<orderEntry type="library" name="Maven: io.netty:netty-all:4.1.10.Final" level="project" /> | ||
<orderEntry type="library" name="Maven: commons-cli:commons-cli:1.4" level="project" /> | ||
</component> | ||
</module> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<source>8</source> | ||
<target>8</target> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-jar-plugin</artifactId> | ||
<version>3.1.0</version> | ||
<configuration> | ||
<archive> | ||
<manifest> | ||
<mainClass>cz.krejcar25.sudoku.Main</mainClass> | ||
</manifest> | ||
</archive> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
<groupId>cz.krejcar25</groupId> | ||
<artifactId>beer.umajkla</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
<dependencies> | ||
<dependency> | ||
<groupId>io.netty</groupId> | ||
<artifactId>netty-all</artifactId> | ||
<version>4.1.10.Final</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>commons-cli</groupId> | ||
<artifactId>commons-cli</artifactId> | ||
<version>1.4</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package beer.umajkla.client; | ||
|
||
import java.io.*; | ||
import java.net.*; | ||
|
||
public class Client implements Runnable { | ||
private Socket socket = null; | ||
private Thread thread = null; | ||
private DataInputStream console = null; | ||
private DataOutputStream streamOut = null; | ||
private ClientThread client = null; | ||
|
||
public Client(String serverName, int serverPort) { | ||
System.out.println("Establishing connection. Please wait ..."); | ||
try { | ||
socket = new Socket(serverName, serverPort); | ||
System.out.println("Connected: " + socket); | ||
start(); | ||
} catch (UnknownHostException e) { | ||
System.out.println("Host unknown: " + e.getMessage()); | ||
} catch (IOException e) { | ||
System.out.println("Unexpected exception: " + e.getMessage()); | ||
} | ||
} | ||
|
||
public void run() { | ||
while (thread != null) { | ||
try { | ||
send(console.readLine()); | ||
} catch (IOException e) { | ||
System.out.println("Sending error: " + e.getMessage()); | ||
stop(); | ||
} | ||
} | ||
} | ||
|
||
public void send(String text) { | ||
try { | ||
streamOut.writeUTF(text); | ||
streamOut.flush(); | ||
} catch (IOException e) { | ||
System.out.println("Sending error: " + e.getMessage()); | ||
stop(); | ||
} | ||
} | ||
|
||
public void handle(String msg) { | ||
if (msg.equals("/bye")) { | ||
System.out.println("Good bye. Press RETURN to exit ..."); | ||
stop(); | ||
} else | ||
System.out.println(msg); | ||
} | ||
|
||
public void start() throws IOException { | ||
console = new DataInputStream(System.in); | ||
streamOut = new DataOutputStream(socket.getOutputStream()); | ||
if (thread == null) { | ||
client = new ClientThread(this, socket); | ||
thread = new Thread(this); | ||
thread.start(); | ||
} | ||
} | ||
|
||
public void stop() { | ||
if (thread != null) { | ||
thread.stop(); | ||
thread = null; | ||
} | ||
try { | ||
if (console != null) console.close(); | ||
if (streamOut != null) streamOut.close(); | ||
if (socket != null) socket.close(); | ||
} catch (IOException e) { | ||
System.out.println("Error closing ..."); | ||
} | ||
client.close(); | ||
client.stop(); | ||
} | ||
} |