Browse Source

Catched some Exceptions and fixed a network error

master
Timo Geier 7 years ago
parent
commit
5c8b16e2d5
  1. 62
      .gitignore
  2. 12
      Online-Chat-Dev.iml
  3. 26
      src/com/vertsys/Client.java
  4. 2
      src/com/vertsys/ClientThread.java
  5. 3
      src/com/vertsys/Server.java

62
.gitignore

@ -0,0 +1,62 @@
# ---> Java
*.class
# Mobile Tools for Java (J2ME)
.mtj.tmp/
# Package Files #
*.jar
*.war
*.ear
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*
# ---> JetBrains
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio
*.iml
## Directory-based project format:
.idea/
# if you remove the above rule, at least ignore the following:
# User-specific stuff:
# .idea/workspace.xml
# .idea/tasks.xml
# .idea/dictionaries
# Sensitive or high-churn files:
# .idea/dataSources.ids
# .idea/dataSources.xml
# .idea/sqlDataSources.xml
# .idea/dynamic.xml
# .idea/uiDesigner.xml
# Gradle:
# .idea/gradle.xml
# .idea/libraries
# Mongo Explorer plugin:
# .idea/mongoSettings.xml
## File-based project format:
*.ipr
*.iws
## Plugin-specific files:
# IntelliJ
/out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties

12
Online-Chat-Dev.iml

@ -1,12 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

26
src/com/vertsys/Client.java

@ -4,14 +4,19 @@ import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.Random;
import static com.vertsys.Server.DEBUG_MODE;
public class Client {
protected static Socket sock;
private static String username;
private static BufferedReader ConsoleIn;
private static final boolean DEBUG_MODE = true;
public static void main(String[] args) {
init();
@ -26,22 +31,33 @@ public class Client {
}
public static void init(){
String hostname = "localhost";
String hostname = null;
try {
hostname = InetAddress.getLocalHost().getHostAddress();
if(DEBUG_MODE)
System.out.println("Host-IP: " + hostname);
} catch (UnknownHostException e) {
e.printStackTrace();
}
int port = 42424;
// Falls die Vergabe eines Benutzernamen fehlschlägt --> "test" + Zufallszahl
Random rand = new Random();
username = "test" + Integer.toString(rand.nextInt(4));
username = "test" + Integer.toString(rand.nextInt());
try {
ConsoleIn = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Your Username: ");
String user = ConsoleIn.readLine();
if (user != "")
if (!user.isEmpty())
username = user;
System.out.print("Enter Server hostname: ");
hostname = ConsoleIn.readLine();
String host = ConsoleIn.readLine();
if(!host.isEmpty())
hostname = host;
System.out.print("Enter port number: ");
port = Integer.parseInt(ConsoleIn.readLine());
String portNum = ConsoleIn.readLine();
if(!portNum.isEmpty())
port = Integer.parseInt(portNum);
}catch (IOException e){
e.printStackTrace();
}

2
src/com/vertsys/ClientThread.java

@ -1,7 +1,5 @@
package com.vertsys;
//import static com.vertsys.Server.sock;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

3
src/com/vertsys/Server.java

@ -8,9 +8,10 @@ import java.util.ArrayList;
public class Server {
protected static ServerSocket sock;
protected static ArrayList<String> messages = new ArrayList<>();
protected static ArrayList<Socket> clients = new ArrayList<>();
// protected static ArrayList<String> messages = new ArrayList<>();
protected static int port;
protected static boolean DEBUG_MODE = true;

Loading…
Cancel
Save