This repository was archived by the owner on Jan 15, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit aae6776
Showing
9 changed files
with
1,209 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- You may freely edit this file. See commented blocks below for --> | ||
<!-- some examples of how to customize the build. --> | ||
<!-- (If you delete it and reopen the project it will be recreated.) --> | ||
<!-- By default, only the Clean and Build commands use this build script. --> | ||
<!-- Commands such as Run, Debug, and Test only use this build script if --> | ||
<!-- the Compile on Save feature is turned off for the project. --> | ||
<!-- You can turn off the Compile on Save (or Deploy on Save) setting --> | ||
<!-- in the project's Project Properties dialog box.--> | ||
<project name="MultiThreadChat-Server" default="default" basedir="."> | ||
<description>Builds, tests, and runs the project MultiThreadChat-Server.</description> | ||
<import file="nbproject/build-impl.xml"/> | ||
<!-- | ||
There exist several targets which are by default empty and which can be | ||
used for execution of your tasks. These targets are usually executed | ||
before and after some main targets. They are: | ||
-pre-init: called before initialization of project properties | ||
-post-init: called after initialization of project properties | ||
-pre-compile: called before javac compilation | ||
-post-compile: called after javac compilation | ||
-pre-compile-single: called before javac compilation of single file | ||
-post-compile-single: called after javac compilation of single file | ||
-pre-compile-test: called before javac compilation of JUnit tests | ||
-post-compile-test: called after javac compilation of JUnit tests | ||
-pre-compile-test-single: called before javac compilation of single JUnit test | ||
-post-compile-test-single: called after javac compilation of single JUunit test | ||
-pre-jar: called before JAR building | ||
-post-jar: called after JAR building | ||
-post-clean: called after cleaning build products | ||
(Targets beginning with '-' are not intended to be called on their own.) | ||
Example of inserting an obfuscator after compilation could look like this: | ||
<target name="-post-compile"> | ||
<obfuscate> | ||
<fileset dir="${build.classes.dir}"/> | ||
</obfuscate> | ||
</target> | ||
For list of available properties check the imported | ||
nbproject/build-impl.xml file. | ||
Another way to customize the build is by overriding existing main targets. | ||
The targets of interest are: | ||
-init-macrodef-javac: defines macro for javac compilation | ||
-init-macrodef-junit: defines macro for junit execution | ||
-init-macrodef-debug: defines macro for class debugging | ||
-init-macrodef-java: defines macro for class execution | ||
-do-jar-with-manifest: JAR building (if you are using a manifest) | ||
-do-jar-without-manifest: JAR building (if you are not using a manifest) | ||
run: execution of project | ||
-javadoc-build: Javadoc generation | ||
test-report: JUnit report generation | ||
An example of overriding the target for project execution could look like this: | ||
<target name="run" depends="MultiThreadChat-Server-impl.jar"> | ||
<exec dir="bin" executable="launcher.exe"> | ||
<arg file="${dist.jar}"/> | ||
</exec> | ||
</target> | ||
Notice that the overridden target depends on the jar target and not only on | ||
the compile target as the regular run target does. Again, for a list of available | ||
properties which you can use, check the target you are overriding in the | ||
nbproject/build-impl.xml file. | ||
--> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
Manifest-Version: 1.0 | ||
X-COMMENT: Main-Class will be added automatically by build | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
build.xml.data.CRC32=85f10eb7 | ||
build.xml.script.CRC32=2fd28c72 | ||
build.xml.stylesheet.CRC32=[email protected] | ||
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml. | ||
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you. | ||
nbproject/build-impl.xml.data.CRC32=85f10eb7 | ||
nbproject/build-impl.xml.script.CRC32=17f07d41 | ||
nbproject/build-impl.xml.stylesheet.CRC32=[email protected] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
compile.on.save=true | ||
user.properties.file=C:\\Users\\Fusion2004\\.netbeans\\6.9\\build.properties |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project-private xmlns="http://www.netbeans.org/ns/project-private/1"> | ||
<editor-bookmarks xmlns="http://www.netbeans.org/ns/editor-bookmarks/1"/> | ||
</project-private> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
annotation.processing.enabled=true | ||
annotation.processing.enabled.in.editor=false | ||
annotation.processing.processor.options= | ||
annotation.processing.processors.list= | ||
annotation.processing.run.all.processors=true | ||
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output | ||
build.classes.dir=${build.dir}/classes | ||
build.classes.excludes=**/*.java,**/*.form | ||
# This directory is removed when the project is cleaned: | ||
build.dir=build | ||
build.generated.dir=${build.dir}/generated | ||
build.generated.sources.dir=${build.dir}/generated-sources | ||
# Only compile against the classpath explicitly listed here: | ||
build.sysclasspath=ignore | ||
build.test.classes.dir=${build.dir}/test/classes | ||
build.test.results.dir=${build.dir}/test/results | ||
# Uncomment to specify the preferred debugger connection transport: | ||
#debug.transport=dt_socket | ||
debug.classpath=\ | ||
${run.classpath} | ||
debug.test.classpath=\ | ||
${run.test.classpath} | ||
# This directory is removed when the project is cleaned: | ||
dist.dir=dist | ||
dist.jar=${dist.dir}/MultiThreadChat-Server.jar | ||
dist.javadoc.dir=${dist.dir}/javadoc | ||
excludes= | ||
includes=** | ||
jar.compress=false | ||
javac.classpath= | ||
# Space-separated list of extra javac options | ||
javac.compilerargs= | ||
javac.deprecation=false | ||
javac.processorpath=\ | ||
${javac.classpath} | ||
javac.source=1.5 | ||
javac.target=1.5 | ||
javac.test.classpath=\ | ||
${javac.classpath}:\ | ||
${build.classes.dir}:\ | ||
${libs.junit.classpath}:\ | ||
${libs.junit_4.classpath} | ||
javac.test.processorpath=\ | ||
${javac.test.classpath} | ||
javadoc.additionalparam= | ||
javadoc.author=false | ||
javadoc.encoding=${source.encoding} | ||
javadoc.noindex=false | ||
javadoc.nonavbar=false | ||
javadoc.notree=false | ||
javadoc.private=false | ||
javadoc.splitindex=true | ||
javadoc.use=true | ||
javadoc.version=false | ||
javadoc.windowtitle= | ||
main.class=MultiThreadChatServer | ||
manifest.file=manifest.mf | ||
meta.inf.dir=${src.dir}/META-INF | ||
platform.active=default_platform | ||
run.classpath=\ | ||
${javac.classpath}:\ | ||
${build.classes.dir} | ||
# Space-separated list of JVM arguments used when running the project | ||
# (you may also define separate properties like run-sys-prop.name=value instead of -Dname=value | ||
# or test-sys-prop.name=value to set system properties for unit tests): | ||
run.jvmargs= | ||
run.test.classpath=\ | ||
${javac.test.classpath}:\ | ||
${build.test.classes.dir} | ||
source.encoding=UTF-8 | ||
src.dir=src | ||
test.src.dir=test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://www.netbeans.org/ns/project/1"> | ||
<type>org.netbeans.modules.java.j2seproject</type> | ||
<configuration> | ||
<data xmlns="http://www.netbeans.org/ns/j2se-project/3"> | ||
<name>MultiThreadChat-Server</name> | ||
<source-roots> | ||
<root id="src.dir"/> | ||
</source-roots> | ||
<test-roots> | ||
<root id="test.src.dir"/> | ||
</test-roots> | ||
</data> | ||
</configuration> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
import java.io.*; | ||
import java.net.*; | ||
|
||
|
||
// This client thread opens the input and the output streams for a particular client, | ||
// ask the client's name, informs all the clients currently connected to the | ||
// server about the fact that a new client has joined the chat room, | ||
// and as long as it receive data, echos that data back to all other clients. | ||
// When the client leaves the chat room this thread informs also all the | ||
// clients about that and terminates. | ||
public class MultiThreadChatServer{ | ||
|
||
// Declaration section: | ||
// declare a server socket and a client socket for the server | ||
// declare an input and an output stream | ||
|
||
static Socket clientSocket = null; | ||
static ServerSocket serverSocket = null; | ||
|
||
// This chat server can accept up to 10 clients' connections | ||
|
||
static clientThread t[] = new clientThread[10]; | ||
|
||
public static void main(String args[]) { | ||
|
||
// The default port | ||
|
||
int port_number=7777; | ||
|
||
if (args.length < 1) | ||
{ | ||
System.out.println("Usage: java MultiThreadChatServer \n"+ | ||
"Now using port number="+port_number); | ||
} else { | ||
port_number=Integer.valueOf(args[0]).intValue(); | ||
} | ||
|
||
// Initialization section: | ||
// Try to open a server socket on port port_number (default 2222) | ||
// Note that we can't choose a port less than 1023 if we are not | ||
// privileged users (root) | ||
|
||
try { | ||
serverSocket = new ServerSocket(port_number); | ||
} | ||
catch (IOException e) | ||
{System.out.println(e);} | ||
|
||
// Create a socket object from the ServerSocket to listen and accept | ||
// connections. | ||
// Open input and output streams for this socket will be created in | ||
// client's thread since every client is served by the server in | ||
// an individual thread | ||
|
||
while(true){ | ||
try { | ||
clientSocket = serverSocket.accept(); | ||
for(int i=0; i<=9; i++){ | ||
if(t[i]==null) | ||
{ | ||
(t[i] = new clientThread(clientSocket,t)).start(); | ||
break; | ||
} | ||
} | ||
} | ||
catch (IOException e) { | ||
System.out.println(e);} | ||
} | ||
} | ||
} | ||
|
||
class clientThread extends Thread{ | ||
|
||
DataInputStream is = null; | ||
PrintStream os = null; | ||
Socket clientSocket = null; | ||
clientThread t[]; | ||
|
||
public clientThread(Socket clientSocket, clientThread[] t){ | ||
this.clientSocket=clientSocket; | ||
this.t=t; | ||
} | ||
|
||
public void run() | ||
{ | ||
String line; | ||
String name; | ||
Boolean ragequit = false; | ||
try{ | ||
is = new DataInputStream(clientSocket.getInputStream()); | ||
os = new PrintStream(clientSocket.getOutputStream()); | ||
os.println("Enter your username:"); | ||
name = is.readLine(); | ||
os.println("Hello "+name+" to our chat room.\nTo leave enter /quit in a new line"); | ||
for(int i=0; i<=9; i++) | ||
if (t[i]!=null && t[i]!=this) | ||
t[i].os.println("*** A new user "+name+" entered the chat room !!! ***" ); | ||
while (true) { | ||
line = is.readLine(); | ||
if(line.startsWith("/quit")) break; | ||
else if(line.startsWith("/ragequit")) { | ||
ragequit = true; | ||
break; | ||
} | ||
for(int i=0; i<=9; i++) | ||
if (t[i]!=null) t[i].os.println("<"+name+"> "+line); | ||
} | ||
for(int i=0; i<=9; i++) | ||
if (t[i]!=null && t[i]!=this) { | ||
if(ragequit) { | ||
t[i].os.println("*** The user "+name+" is RAGEQUITTING!11!!1!ONE1!!1 ***" ); | ||
} else { | ||
t[i].os.println("*** The user "+name+" is leaving the chat room !!! ***" ); | ||
} | ||
} | ||
|
||
if(ragequit) | ||
os.println("*** RAAAAAAAAAAAAAAAAAAAAAAAAAAAAGE ***"); | ||
else | ||
os.println("*** Bye "+name+" ***"); | ||
|
||
os.println("/quit"); | ||
// Clean up: | ||
// Set to null the current thread variable such that other client could | ||
// be accepted by the server | ||
|
||
for(int i=0; i<=9; i++) | ||
if (t[i]==this) t[i]=null; | ||
|
||
// close the output stream | ||
// close the input stream | ||
// close the socket | ||
|
||
is.close(); | ||
os.close(); | ||
clientSocket.close(); | ||
} | ||
catch(IOException e){}; | ||
} | ||
} |