Skip to content

Commit 9465fa7

Browse files
author
Wan Jong
committedMay 2, 2017
Added Server and Message
1 parent 89b463c commit 9465fa7

9 files changed

+156
-34
lines changed
 

‎.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/nbproject/private/

‎nbproject/build-impl.xml

+11-10
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ is divided into following sections:
4646
<property file="${user.properties.file}"/>
4747
<!-- The two properties below are usually overridden -->
4848
<!-- by the active platform. Just a fallback. -->
49-
<property name="default.javac.source" value="1.4"/>
50-
<property name="default.javac.target" value="1.4"/>
49+
<property name="default.javac.source" value="1.6"/>
50+
<property name="default.javac.target" value="1.6"/>
5151
</target>
5252
<target depends="-pre-init,-init-private,-init-user" name="-init-project">
5353
<property file="nbproject/configs/${config}.properties"/>
@@ -76,7 +76,7 @@ is divided into following sections:
7676
<and>
7777
<isset property="javac.profile"/>
7878
<length length="0" string="${javac.profile}" when="greater"/>
79-
<matches pattern="1\.[89](\..*)?" string="${javac.source}"/>
79+
<matches pattern="((1\.[89])|9)(\..*)?" string="${javac.source}"/>
8080
</and>
8181
</condition>
8282
<condition property="do.archive">
@@ -156,6 +156,7 @@ is divided into following sections:
156156
<property name="application.args" value=""/>
157157
<property name="source.encoding" value="${file.encoding}"/>
158158
<property name="runtime.encoding" value="${source.encoding}"/>
159+
<property name="manifest.encoding" value="${source.encoding}"/>
159160
<condition property="javadoc.encoding.used" value="${javadoc.encoding}">
160161
<and>
161162
<isset property="javadoc.encoding"/>
@@ -840,7 +841,7 @@ is divided into following sections:
840841
</chainedmapper>
841842
</pathconvert>
842843
<taskdef classname="org.netbeans.modules.java.j2seproject.copylibstask.CopyLibs" classpath="${libs.CopyLibs.classpath}" name="copylibs"/>
843-
<copylibs compress="${jar.compress}" excludeFromCopy="${copylibs.excludes}" index="${jar.index}" indexMetaInf="${jar.index.metainf}" jarfile="${dist.jar}" manifest="@{manifest}" rebase="${copylibs.rebase}" runtimeclasspath="${run.classpath.without.build.classes.dir}">
844+
<copylibs compress="${jar.compress}" excludeFromCopy="${copylibs.excludes}" index="${jar.index}" indexMetaInf="${jar.index.metainf}" jarfile="${dist.jar}" manifest="@{manifest}" manifestencoding="UTF-8" rebase="${copylibs.rebase}" runtimeclasspath="${run.classpath.without.build.classes.dir}">
844845
<fileset dir="${build.classes.dir}" excludes="${dist.archive.excludes}"/>
845846
<manifest>
846847
<attribute name="Class-Path" value="${jar.classpath}"/>
@@ -852,7 +853,7 @@ is divided into following sections:
852853
</target>
853854
<target name="-init-presetdef-jar">
854855
<presetdef name="jar" uri="http://www.netbeans.org/ns/j2se-project/1">
855-
<jar compress="${jar.compress}" index="${jar.index}" jarfile="${dist.jar}">
856+
<jar compress="${jar.compress}" index="${jar.index}" jarfile="${dist.jar}" manifestencoding="UTF-8">
856857
<j2seproject1:fileset dir="${build.classes.dir}" excludes="${dist.archive.excludes}"/>
857858
</jar>
858859
</presetdef>
@@ -975,23 +976,23 @@ is divided into following sections:
975976
</target>
976977
<target depends="init" if="do.archive+manifest.available" name="-do-jar-copy-manifest">
977978
<tempfile deleteonexit="true" destdir="${build.dir}" property="tmp.manifest.file"/>
978-
<copy file="${manifest.file}" tofile="${tmp.manifest.file}"/>
979+
<copy encoding="${manifest.encoding}" file="${manifest.file}" outputencoding="UTF-8" tofile="${tmp.manifest.file}"/>
979980
</target>
980981
<target depends="init,-do-jar-create-manifest,-do-jar-copy-manifest" if="do.archive+main.class.available" name="-do-jar-set-mainclass">
981-
<manifest file="${tmp.manifest.file}" mode="update">
982+
<manifest encoding="UTF-8" file="${tmp.manifest.file}" mode="update">
982983
<attribute name="Main-Class" value="${main.class}"/>
983984
</manifest>
984985
</target>
985986
<target depends="init,-do-jar-create-manifest,-do-jar-copy-manifest" if="do.archive+profile.available" name="-do-jar-set-profile">
986-
<manifest file="${tmp.manifest.file}" mode="update">
987+
<manifest encoding="UTF-8" file="${tmp.manifest.file}" mode="update">
987988
<attribute name="Profile" value="${javac.profile}"/>
988989
</manifest>
989990
</target>
990991
<target depends="init,-do-jar-create-manifest,-do-jar-copy-manifest" if="do.archive+splashscreen.available" name="-do-jar-set-splashscreen">
991992
<basename file="${application.splash}" property="splashscreen.basename"/>
992993
<mkdir dir="${build.classes.dir}/META-INF"/>
993994
<copy failonerror="false" file="${application.splash}" todir="${build.classes.dir}/META-INF"/>
994-
<manifest file="${tmp.manifest.file}" mode="update">
995+
<manifest encoding="UTF-8" file="${tmp.manifest.file}" mode="update">
995996
<attribute name="SplashScreen-Image" value="META-INF/${splashscreen.basename}"/>
996997
</manifest>
997998
</target>
@@ -1186,7 +1187,7 @@ is divided into following sections:
11861187
<target depends="-profile-check" description="Profile a selected class in the IDE." if="profiler.configured" name="profile-test-with-main">
11871188
<fail unless="run.class">Must select one file in the IDE or set run.class</fail>
11881189
<startprofiler/>
1189-
<antcal target="run-test-with-main"/>
1190+
<antcall target="run-test-with-main"/>
11901191
</target>
11911192
<target depends="-profile-check,-profile-applet-pre72" if="profiler.configured" name="profile-applet" unless="profiler.info.jvmargs.agent">
11921193
<fail unless="applet.url">Must select one file in the IDE or set applet.url</fail>

‎nbproject/genfiles.properties

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ build.xml.stylesheet.CRC32=8064a381@1.79.1.48
44
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
55
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
66
nbproject/build-impl.xml.data.CRC32=4f8b0d0f
7-
nbproject/build-impl.xml.script.CRC32=aece8a60
8-
nbproject/build-impl.xml.stylesheet.CRC32=05530350@1.79.1.48
7+
nbproject/build-impl.xml.script.CRC32=b66c8e91
8+
nbproject/build-impl.xml.stylesheet.CRC32=830a3534@1.80.1.48

‎nbproject/project.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ javadoc.splitindex=true
5454
javadoc.use=true
5555
javadoc.version=false
5656
javadoc.windowtitle=
57-
main.class=cse310.project.CSE310Project
57+
main.class=cse310.project.Server
5858
manifest.file=manifest.mf
5959
meta.inf.dir=${src.dir}/META-INF
6060
mkdist.disabled=false

‎src/Constants/MessageType.java

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
package Constants;
7+
8+
/**
9+
*
10+
* @author Shawn
11+
*/
12+
public enum MessageType {
13+
HELP, LOGIN, PLACE, EXIT;
14+
}

‎src/Messages/Message.java

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
package Messages;
7+
8+
import Constants.MessageType;
9+
import java.io.Serializable;
10+
11+
/**
12+
*
13+
* @author Shawn
14+
*/
15+
public class Message implements Serializable {
16+
private MessageType type;
17+
private String info;
18+
19+
public String getInfo() {
20+
return info;
21+
}
22+
23+
public void setInfo(String info) {
24+
this.info = info;
25+
}
26+
27+
public MessageType getType() {
28+
return type;
29+
}
30+
31+
public void setType(MessageType type) {
32+
this.type = type;
33+
}
34+
}
35+

‎src/cse310/project/CSE310Project.java

-21
This file was deleted.

‎src/cse310/project/Server.java

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package cse310.project;
2+
3+
import Constants.MessageType;
4+
import Messages.Message;
5+
import java.io.IOException;
6+
import java.io.ObjectInputStream;
7+
import java.io.ObjectOutputStream;
8+
import java.net.ServerSocket;
9+
import java.net.Socket;
10+
import java.util.logging.Level;
11+
import java.util.logging.Logger;
12+
13+
/**
14+
*
15+
* @author Shawn
16+
*/
17+
public class Server {
18+
19+
private static volatile boolean running = true;
20+
private static final int port = 25564;
21+
private static ServerSocket ss;
22+
23+
public static void main(String[] args) {
24+
try {
25+
ss = new ServerSocket(port);
26+
while(running && !ss.isClosed()) {
27+
Socket s = ss.accept();
28+
ServerCommunication t = new ServerCommunication(s);
29+
Thread th = new Thread(t);
30+
th.start();
31+
}
32+
} catch(IOException ex) {
33+
Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex);
34+
}
35+
}
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
package cse310.project;
7+
8+
import Constants.MessageType;
9+
import Messages.Message;
10+
import java.io.IOException;
11+
import java.io.ObjectInputStream;
12+
import java.io.ObjectOutputStream;
13+
import java.net.Socket;
14+
import java.util.logging.Level;
15+
import java.util.logging.Logger;
16+
17+
/**
18+
*
19+
* @author Shawn
20+
*/
21+
public class ServerCommunication implements Runnable {
22+
private Socket s;
23+
private volatile boolean running;
24+
private ObjectInputStream ois;
25+
private ObjectOutputStream oos;
26+
27+
public ServerCommunication(Socket s) {
28+
this.s = s;
29+
}
30+
31+
@Override
32+
public void run() {
33+
try {
34+
ois = new ObjectInputStream(s.getInputStream());
35+
oos = new ObjectOutputStream(s.getOutputStream());
36+
} catch (IOException ex) {
37+
Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex);
38+
}
39+
while(running) {
40+
try {
41+
Message m = (Message) ois.readObject();
42+
if(m.getType() == MessageType.HELP) {
43+
44+
}
45+
} catch (IOException ex) {
46+
Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex);
47+
} catch (ClassNotFoundException ex) {
48+
Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex);
49+
}
50+
}
51+
}
52+
53+
public void setRunning(boolean running) {
54+
this.running = running;
55+
}
56+
}

0 commit comments

Comments
 (0)
Please sign in to comment.