esoe 2 years ago
parent
commit
c51eaededa
  1. 73
      java/samples/tcp/Chat/ChatClientJ130_lesson4_group1/build.xml
  2. 4
      java/samples/tcp/Chat/ChatClientJ130_lesson4_group1/build/built-jar.properties
  3. 0
      java/samples/tcp/Chat/ChatClientJ130_lesson4_group1/build/classes/.netbeans_automatic_build
  4. 0
      java/samples/tcp/Chat/ChatClientJ130_lesson4_group1/build/classes/.netbeans_update_resources
  5. BIN
      java/samples/tcp/Chat/ChatClientJ130_lesson4_group1/build/classes/chatclientj130_lesson4_group1/ChatServer.class
  6. BIN
      java/samples/tcp/Chat/ChatClientJ130_lesson4_group1/build/classes/chatclientj130_lesson4_group1/ClientFrame.class
  7. BIN
      java/samples/tcp/Chat/ChatClientJ130_lesson4_group1/build/classes/chatclientj130_lesson4_group1/ClientProperties.class
  8. BIN
      java/samples/tcp/Chat/ChatClientJ130_lesson4_group1/build/classes/chatclientj130_lesson4_group1/MainClass.class
  9. 2
      java/samples/tcp/Chat/ChatClientJ130_lesson4_group1/client.property
  10. BIN
      java/samples/tcp/Chat/ChatClientJ130_lesson4_group1/dist/ChatClientJ130_lesson4_group1.jar
  11. 32
      java/samples/tcp/Chat/ChatClientJ130_lesson4_group1/dist/README.TXT
  12. 2
      java/samples/tcp/Chat/ChatClientJ130_lesson4_group1/dist/client.property
  13. 3
      java/samples/tcp/Chat/ChatClientJ130_lesson4_group1/manifest.mf
  14. 1420
      java/samples/tcp/Chat/ChatClientJ130_lesson4_group1/nbproject/build-impl.xml
  15. 8
      java/samples/tcp/Chat/ChatClientJ130_lesson4_group1/nbproject/genfiles.properties
  16. 2
      java/samples/tcp/Chat/ChatClientJ130_lesson4_group1/nbproject/private/private.properties
  17. 12
      java/samples/tcp/Chat/ChatClientJ130_lesson4_group1/nbproject/private/private.xml
  18. 74
      java/samples/tcp/Chat/ChatClientJ130_lesson4_group1/nbproject/project.properties
  19. 15
      java/samples/tcp/Chat/ChatClientJ130_lesson4_group1/nbproject/project.xml
  20. 125
      java/samples/tcp/Chat/ChatClientJ130_lesson4_group1/src/chatclientj130_lesson4_group1/ChatServer.java
  21. 93
      java/samples/tcp/Chat/ChatClientJ130_lesson4_group1/src/chatclientj130_lesson4_group1/ClientFrame.java
  22. 73
      java/samples/tcp/Chat/ChatClientJ130_lesson4_group1/src/chatclientj130_lesson4_group1/ClientProperties.java
  23. 21
      java/samples/tcp/Chat/ChatClientJ130_lesson4_group1/src/chatclientj130_lesson4_group1/MainClass.java
  24. 73
      java/samples/tcp/Chat/ChatServerJ130_lesson4_group1/build.xml
  25. 4
      java/samples/tcp/Chat/ChatServerJ130_lesson4_group1/build/built-jar.properties
  26. BIN
      java/samples/tcp/Chat/ChatServerJ130_lesson4_group1/build/classes/chatserverj130_lesson4_group1/ClientSocket.class
  27. BIN
      java/samples/tcp/Chat/ChatServerJ130_lesson4_group1/build/classes/chatserverj130_lesson4_group1/MainClass.class
  28. BIN
      java/samples/tcp/Chat/ChatServerJ130_lesson4_group1/build/classes/chatserverj130_lesson4_group1/Message.class
  29. BIN
      java/samples/tcp/Chat/ChatServerJ130_lesson4_group1/build/classes/chatserverj130_lesson4_group1/MessageStore.class
  30. BIN
      java/samples/tcp/Chat/ChatServerJ130_lesson4_group1/build/classes/chatserverj130_lesson4_group1/PortListener.class
  31. BIN
      java/samples/tcp/Chat/ChatServerJ130_lesson4_group1/dist/ChatServerJ130_lesson4_group1.jar
  32. 32
      java/samples/tcp/Chat/ChatServerJ130_lesson4_group1/dist/README.TXT
  33. 3
      java/samples/tcp/Chat/ChatServerJ130_lesson4_group1/manifest.mf
  34. 1420
      java/samples/tcp/Chat/ChatServerJ130_lesson4_group1/nbproject/build-impl.xml
  35. 8
      java/samples/tcp/Chat/ChatServerJ130_lesson4_group1/nbproject/genfiles.properties
  36. 2
      java/samples/tcp/Chat/ChatServerJ130_lesson4_group1/nbproject/private/private.properties
  37. 10
      java/samples/tcp/Chat/ChatServerJ130_lesson4_group1/nbproject/private/private.xml
  38. 74
      java/samples/tcp/Chat/ChatServerJ130_lesson4_group1/nbproject/project.properties
  39. 15
      java/samples/tcp/Chat/ChatServerJ130_lesson4_group1/nbproject/project.xml
  40. 62
      java/samples/tcp/Chat/ChatServerJ130_lesson4_group1/src/chatserverj130_lesson4_group1/ClientSocket.java
  41. 25
      java/samples/tcp/Chat/ChatServerJ130_lesson4_group1/src/chatserverj130_lesson4_group1/MainClass.java
  42. 85
      java/samples/tcp/Chat/ChatServerJ130_lesson4_group1/src/chatserverj130_lesson4_group1/Message.java
  43. 49
      java/samples/tcp/Chat/ChatServerJ130_lesson4_group1/src/chatserverj130_lesson4_group1/MessageStore.java
  44. 57
      java/samples/tcp/Chat/ChatServerJ130_lesson4_group1/src/chatserverj130_lesson4_group1/PortListener.java
  45. 73
      java/samples/tcp/Chat2/ChatClientJ130_lesson4_group2/build.xml
  46. 4
      java/samples/tcp/Chat2/ChatClientJ130_lesson4_group2/build/built-jar.properties
  47. BIN
      java/samples/tcp/Chat2/ChatClientJ130_lesson4_group2/build/classes/chatclientj130_lesson4_group2/ChatServer.class
  48. BIN
      java/samples/tcp/Chat2/ChatClientJ130_lesson4_group2/build/classes/chatclientj130_lesson4_group2/ClientFrame.class
  49. BIN
      java/samples/tcp/Chat2/ChatClientJ130_lesson4_group2/build/classes/chatclientj130_lesson4_group2/ClientProperties.class
  50. BIN
      java/samples/tcp/Chat2/ChatClientJ130_lesson4_group2/build/classes/chatclientj130_lesson4_group2/MainClass.class
  51. 2
      java/samples/tcp/Chat2/ChatClientJ130_lesson4_group2/client.property
  52. BIN
      java/samples/tcp/Chat2/ChatClientJ130_lesson4_group2/dist/ChatClientJ130_lesson4_group2.jar
  53. 32
      java/samples/tcp/Chat2/ChatClientJ130_lesson4_group2/dist/README.TXT
  54. 3
      java/samples/tcp/Chat2/ChatClientJ130_lesson4_group2/manifest.mf
  55. 1420
      java/samples/tcp/Chat2/ChatClientJ130_lesson4_group2/nbproject/build-impl.xml
  56. 8
      java/samples/tcp/Chat2/ChatClientJ130_lesson4_group2/nbproject/genfiles.properties
  57. 2
      java/samples/tcp/Chat2/ChatClientJ130_lesson4_group2/nbproject/private/private.properties
  58. 74
      java/samples/tcp/Chat2/ChatClientJ130_lesson4_group2/nbproject/project.properties
  59. 15
      java/samples/tcp/Chat2/ChatClientJ130_lesson4_group2/nbproject/project.xml
  60. 111
      java/samples/tcp/Chat2/ChatClientJ130_lesson4_group2/src/chatclientj130_lesson4_group2/ChatServer.java
  61. 92
      java/samples/tcp/Chat2/ChatClientJ130_lesson4_group2/src/chatclientj130_lesson4_group2/ClientFrame.java
  62. 73
      java/samples/tcp/Chat2/ChatClientJ130_lesson4_group2/src/chatclientj130_lesson4_group2/ClientProperties.java
  63. 21
      java/samples/tcp/Chat2/ChatClientJ130_lesson4_group2/src/chatclientj130_lesson4_group2/MainClass.java
  64. 73
      java/samples/tcp/Chat2/ChatServerJ130_lesson4_group2/build.xml
  65. 4
      java/samples/tcp/Chat2/ChatServerJ130_lesson4_group2/build/built-jar.properties
  66. BIN
      java/samples/tcp/Chat2/ChatServerJ130_lesson4_group2/build/classes/chatserverj130_lesson4_group2/ClientSocket.class
  67. BIN
      java/samples/tcp/Chat2/ChatServerJ130_lesson4_group2/build/classes/chatserverj130_lesson4_group2/MainClass.class
  68. BIN
      java/samples/tcp/Chat2/ChatServerJ130_lesson4_group2/build/classes/chatserverj130_lesson4_group2/Message.class
  69. BIN
      java/samples/tcp/Chat2/ChatServerJ130_lesson4_group2/build/classes/chatserverj130_lesson4_group2/MessageStore.class
  70. BIN
      java/samples/tcp/Chat2/ChatServerJ130_lesson4_group2/build/classes/chatserverj130_lesson4_group2/PortListener.class
  71. BIN
      java/samples/tcp/Chat2/ChatServerJ130_lesson4_group2/dist/ChatServerJ130_lesson4_group2.jar
  72. 32
      java/samples/tcp/Chat2/ChatServerJ130_lesson4_group2/dist/README.TXT
  73. 3
      java/samples/tcp/Chat2/ChatServerJ130_lesson4_group2/manifest.mf
  74. 1420
      java/samples/tcp/Chat2/ChatServerJ130_lesson4_group2/nbproject/build-impl.xml
  75. 8
      java/samples/tcp/Chat2/ChatServerJ130_lesson4_group2/nbproject/genfiles.properties
  76. 2
      java/samples/tcp/Chat2/ChatServerJ130_lesson4_group2/nbproject/private/private.properties
  77. 74
      java/samples/tcp/Chat2/ChatServerJ130_lesson4_group2/nbproject/project.properties
  78. 15
      java/samples/tcp/Chat2/ChatServerJ130_lesson4_group2/nbproject/project.xml
  79. 42
      java/samples/tcp/Chat2/ChatServerJ130_lesson4_group2/src/chatserverj130_lesson4_group2/ClientSocket.java
  80. 34
      java/samples/tcp/Chat2/ChatServerJ130_lesson4_group2/src/chatserverj130_lesson4_group2/MainClass.java
  81. 85
      java/samples/tcp/Chat2/ChatServerJ130_lesson4_group2/src/chatserverj130_lesson4_group2/Message.java
  82. 48
      java/samples/tcp/Chat2/ChatServerJ130_lesson4_group2/src/chatserverj130_lesson4_group2/MessageStore.java
  83. 52
      java/samples/tcp/Chat2/ChatServerJ130_lesson4_group2/src/chatserverj130_lesson4_group2/PortListener.java
  84. 73
      java/samples/tcp/NetworkTransfer/NetworkTransferClient/build.xml
  85. 0
      java/samples/tcp/NetworkTransfer/NetworkTransferClient/build/classes/.netbeans_automatic_build
  86. 0
      java/samples/tcp/NetworkTransfer/NetworkTransferClient/build/classes/.netbeans_update_resources
  87. BIN
      java/samples/tcp/NetworkTransfer/NetworkTransferClient/build/classes/networktransferclient/NetworkTransferClient.class
  88. BIN
      java/samples/tcp/NetworkTransfer/NetworkTransferClient/j130-lab1.pdf
  89. BIN
      java/samples/tcp/NetworkTransfer/NetworkTransferClient/j130-lab2-2.pdf
  90. BIN
      java/samples/tcp/NetworkTransfer/NetworkTransferClient/j130-lab2.pdf
  91. BIN
      java/samples/tcp/NetworkTransfer/NetworkTransferClient/j130-lab3.pdf
  92. BIN
      java/samples/tcp/NetworkTransfer/NetworkTransferClient/j130-lab4.pdf
  93. 3
      java/samples/tcp/NetworkTransfer/NetworkTransferClient/manifest.mf
  94. 1420
      java/samples/tcp/NetworkTransfer/NetworkTransferClient/nbproject/build-impl.xml
  95. 8
      java/samples/tcp/NetworkTransfer/NetworkTransferClient/nbproject/genfiles.properties
  96. 2
      java/samples/tcp/NetworkTransfer/NetworkTransferClient/nbproject/private/private.properties
  97. 74
      java/samples/tcp/NetworkTransfer/NetworkTransferClient/nbproject/project.properties
  98. 15
      java/samples/tcp/NetworkTransfer/NetworkTransferClient/nbproject/project.xml
  99. 52
      java/samples/tcp/NetworkTransfer/NetworkTransferClient/src/networktransferclient/NetworkTransferClient.java
  100. 73
      java/samples/tcp/NetworkTransfer/NetworkTransferServer/build.xml
  101. Some files were not shown because too many files have changed in this diff Show More

73
java/samples/tcp/Chat/ChatClientJ130_lesson4_group1/build.xml

@ -0,0 +1,73 @@
<?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="ChatClientJ130_lesson4_group1" default="default" basedir=".">
<description>Builds, tests, and runs the project ChatClientJ130_lesson4_group1.</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: JAR building
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="ChatClientJ130_lesson4_group1-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>

4
java/samples/tcp/Chat/ChatClientJ130_lesson4_group1/build/built-jar.properties

@ -0,0 +1,4 @@
#Wed, 25 Jan 2023 21:23:33 +0300
C\:\\Users\\denis.LAPTOP-4LI8UQ4O\\OneDrive\\\u0414\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b\\NetBeansProjects\\ChatClientJ130_lesson4_group1=

0
java/samples/tcp/Chat/ChatClientJ130_lesson4_group1/build/classes/.netbeans_automatic_build

0
java/samples/tcp/Chat/ChatClientJ130_lesson4_group1/build/classes/.netbeans_update_resources

BIN
java/samples/tcp/Chat/ChatClientJ130_lesson4_group1/build/classes/chatclientj130_lesson4_group1/ChatServer.class

Binary file not shown.

BIN
java/samples/tcp/Chat/ChatClientJ130_lesson4_group1/build/classes/chatclientj130_lesson4_group1/ClientFrame.class

Binary file not shown.

BIN
java/samples/tcp/Chat/ChatClientJ130_lesson4_group1/build/classes/chatclientj130_lesson4_group1/ClientProperties.class

Binary file not shown.

BIN
java/samples/tcp/Chat/ChatClientJ130_lesson4_group1/build/classes/chatclientj130_lesson4_group1/MainClass.class

Binary file not shown.

2
java/samples/tcp/Chat/ChatClientJ130_lesson4_group1/client.property

@ -0,0 +1,2 @@
#Wed Jan 25 16:16:48 MSK 2023
username=Denis

BIN
java/samples/tcp/Chat/ChatClientJ130_lesson4_group1/dist/ChatClientJ130_lesson4_group1.jar vendored

Binary file not shown.

32
java/samples/tcp/Chat/ChatClientJ130_lesson4_group1/dist/README.TXT vendored

@ -0,0 +1,32 @@
========================
BUILD OUTPUT DESCRIPTION
========================
When you build an Java application project that has a main class, the IDE
automatically copies all of the JAR
files on the projects classpath to your projects dist/lib folder. The IDE
also adds each of the JAR files to the Class-Path element in the application
JAR files manifest file (MANIFEST.MF).
To run the project from the command line, go to the dist folder and
type the following:
java -jar "ChatClientJ130_lesson4_group1.jar"
To distribute this project, zip up the dist folder (including the lib folder)
and distribute the ZIP file.
Notes:
* If two JAR files on the project classpath have the same name, only the first
JAR file is copied to the lib folder.
* Only JAR files are copied to the lib folder.
If the classpath contains other types of files or folders, these files (folders)
are not copied.
* If a library on the projects classpath also has a Class-Path element
specified in the manifest,the content of the Class-Path element has to be on
the projects runtime path.
* To set a main class in a standard Java project, right-click the project node
in the Projects window and choose Properties. Then click Run and enter the
class name in the Main Class field. Alternatively, you can manually type the
class name in the manifest Main-Class element.

2
java/samples/tcp/Chat/ChatClientJ130_lesson4_group1/dist/client.property vendored

@ -0,0 +1,2 @@
#Wed Jan 25 21:23:49 MSK 2023
username=Denis

3
java/samples/tcp/Chat/ChatClientJ130_lesson4_group1/manifest.mf

@ -0,0 +1,3 @@
Manifest-Version: 1.0
X-COMMENT: Main-Class will be added automatically by build

1420
java/samples/tcp/Chat/ChatClientJ130_lesson4_group1/nbproject/build-impl.xml

File diff suppressed because it is too large Load Diff

8
java/samples/tcp/Chat/ChatClientJ130_lesson4_group1/nbproject/genfiles.properties

@ -0,0 +1,8 @@
build.xml.data.CRC32=016dcbec
build.xml.script.CRC32=9c6d8abd
build.xml.stylesheet.CRC32=8064a381@1.80.1.48
# 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=016dcbec
nbproject/build-impl.xml.script.CRC32=5111007c
nbproject/build-impl.xml.stylesheet.CRC32=830a3534@1.80.1.48

2
java/samples/tcp/Chat/ChatClientJ130_lesson4_group1/nbproject/private/private.properties

@ -0,0 +1,2 @@
compile.on.save=true
user.properties.file=C:\\Users\\denis.LAPTOP-4LI8UQ4O\\AppData\\Roaming\\NetBeans\\8.2\\build.properties

12
java/samples/tcp/Chat/ChatClientJ130_lesson4_group1/nbproject/private/private.xml

@ -0,0 +1,12 @@
<?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/2" lastBookmarkId="0"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group>
<file>file:/C:/Users/denis.LAPTOP-4LI8UQ4O/OneDrive/Документы/NetBeansProjects/ChatClientJ130_lesson4_group1/src/chatclientj130_lesson4_group1/ChatServer.java</file>
<file>file:/C:/Users/denis.LAPTOP-4LI8UQ4O/OneDrive/Документы/NetBeansProjects/ChatClientJ130_lesson4_group1/src/chatclientj130_lesson4_group1/MainClass.java</file>
<file>file:/C:/Users/denis.LAPTOP-4LI8UQ4O/OneDrive/Документы/NetBeansProjects/ChatClientJ130_lesson4_group1/src/chatclientj130_lesson4_group1/ClientFrame.java</file>
<file>file:/C:/Users/denis.LAPTOP-4LI8UQ4O/OneDrive/Документы/NetBeansProjects/ChatClientJ130_lesson4_group1/src/chatclientj130_lesson4_group1/ClientProperties.java</file>
</group>
</open-files>
</project-private>

74
java/samples/tcp/Chat/ChatClientJ130_lesson4_group1/nbproject/project.properties

@ -0,0 +1,74 @@
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}
# \u0424\u0430\u0439\u043b\u044b \u0432 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0435 build.classes.dir, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0438\u0437 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u044f\u0435\u043c\u043e\u0433\u043e \u0430\u0440\u0445\u0438\u0432\u0430 jar
dist.archive.excludes=
# This directory is removed when the project is cleaned:
dist.dir=dist
dist.jar=${dist.dir}/ChatClientJ130_lesson4_group1.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.external.vm=true
javac.processorpath=\
${javac.classpath}
javac.source=1.8
javac.target=1.8
javac.test.classpath=\
${javac.classpath}:\
${build.classes.dir}
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=chatclientj130_lesson4_group1.MainClass
manifest.file=manifest.mf
meta.inf.dir=${src.dir}/META-INF
mkdist.disabled=false
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.
# To set system properties for unit tests define test-sys-prop.name=value:
run.jvmargs=
run.test.classpath=\
${javac.test.classpath}:\
${build.test.classes.dir}
source.encoding=UTF-8
src.dir=src
test.src.dir=test

15
java/samples/tcp/Chat/ChatClientJ130_lesson4_group1/nbproject/project.xml

@ -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>ChatClientJ130_lesson4_group1</name>
<source-roots>
<root id="src.dir"/>
</source-roots>
<test-roots>
<root id="test.src.dir"/>
</test-roots>
</data>
</configuration>
</project>

125
java/samples/tcp/Chat/ChatClientJ130_lesson4_group1/src/chatclientj130_lesson4_group1/ChatServer.java

@ -0,0 +1,125 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package chatclientj130_lesson4_group1;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.Socket;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JLabel;
import javax.swing.JTextArea;
/**
*
* @author Denis
*/
public class ChatServer implements Runnable{
private static ChatServer chatServer;
private boolean isExit = false;
private JLabel topLabel;
private JTextArea chatingText;
private ChatServer(JLabel topLabel, JTextArea chatingText){
this.chatingText = chatingText;
this.topLabel = topLabel;
}
public static ChatServer getState(JLabel topLabel, JTextArea chatingText){
Thread thread = null;
if(chatServer==null) {
chatServer = new ChatServer(topLabel, chatingText);
thread = new Thread(chatServer);
thread.start();
}
if(thread!=null && thread.getState().toString().equals("TERMINATED")){
thread = new Thread(chatServer);
thread.start();
}
return chatServer;
}
@Override
public void run() {
while(!isExit){
updateChat();
try {Thread.sleep(1000);} catch (InterruptedException ex) {}
}
}
private void updateChat(){
try (Socket socket = new Socket(ClientProperties.getState().getServerHost(), ClientProperties.getState().getServerPort());
InputStream is = socket.getInputStream();
OutputStream os = socket.getOutputStream();){
//BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));){
String labelText = topLabel.getText();
if(socket.isConnected()) topLabel.setText("<html><font color='green'>" + labelText + "</font></html>");
//writer.write("get messages\n");
os.write("get messages".getBytes());
socket.shutdownOutput();
//writer.flush();
byte[] buffer = new byte[1024];
int length;
StringBuilder sb = new StringBuilder();
while((length=is.read(buffer))>-1){
sb.append(new String(buffer, 0, length));
}
String answer = sb.toString();
chatingText.setText(answer);
} catch (IOException ex) {
String labelText = topLabel.getText();
topLabel.setText("<html><font color='red'>" + labelText + "</font></html>");
Logger.getLogger(MainClass.class.getName()).log(Level.SEVERE, null, ex);
}
}
public void sendMessage(String message){
String username = ClientProperties.getState().getUsername();
message = "post" + username + " >> " + getCurrentTime() + " >> " + message;
try (Socket socket = new Socket(ClientProperties.getState().getServerHost(), ClientProperties.getState().getServerPort());
InputStream is = socket.getInputStream();
OutputStream os = socket.getOutputStream();){
//BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));){
String labelText = topLabel.getText();
if(socket.isConnected()) topLabel.setText("<html><font color='green'>" + labelText + "</font></html>");
System.out.println(message);
os.write(message.getBytes());
//writer.write(message + "\n");
socket.shutdownOutput();
byte[] buffer = new byte[1024];
int length;
StringBuilder sb = new StringBuilder();
while((length=is.read(buffer))>-1){
sb.append(new String(buffer, 0, length));
}
String answer = sb.toString();
System.out.println(answer);
} catch (IOException ex) {
String labelText = topLabel.getText();
topLabel.setText("<html><font color='red'>" + labelText + "</font></html>");
Logger.getLogger(MainClass.class.getName()).log(Level.SEVERE, null, ex);
}
}
private String getCurrentTime(){
Date currentDate = new Date(System.currentTimeMillis());
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy:MM:dd hh:mm:ss");
String time = dateFormat.format(currentDate);
return time;
}
public void exit(){
isExit = true;
}
}

93
java/samples/tcp/Chat/ChatClientJ130_lesson4_group1/src/chatclientj130_lesson4_group1/ClientFrame.java

@ -0,0 +1,93 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package chatclientj130_lesson4_group1;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import javax.swing.*;
/**
*
* @author Denis
*/
public class ClientFrame extends JFrame{
private final JMenuBar menuBar;
private final JMenu menu;
private final JMenuItem itemExit;
private final JMenuItem itemServerHost;
private final JButton send;
private final JTextField messageText;
private final JTextArea chatingText;
private final JLabel topLabel;
private String serverHost;
private int serverPort;
private String username;
public ClientFrame(){
super("Chat client");
setSize(500, 700);
setDefaultCloseOperation(EXIT_ON_CLOSE);
getSettings();
setLayout(new BorderLayout());
topLabel = new JLabel(serverHost + ":" + serverPort + " >>> " + username);
if(username==null) {
ClientProperties.getState().setUsername(JOptionPane.showInputDialog(this, "Введите имя пользователя"));
getSettings();
topLabel.setText(serverHost + ":" + serverPort + " >>> " + username);
}
menuBar = new JMenuBar();
menu = new JMenu("File");
itemExit = new JMenuItem("Exit");
itemServerHost = new JMenuItem("Server settings");
setJMenuBar(menuBar);
menuBar.add(menu);
menu.add(itemExit);
menu.add(itemServerHost);
chatingText = new JTextArea();
messageText = new JTextField(" ");
send = new JButton("Send");
add(topLabel, BorderLayout.NORTH);
chatingText.setEditable(false);
add(chatingText, BorderLayout.CENTER);
messageText.setColumns(30);
JPanel bottom = new JPanel(new FlowLayout());
bottom.add(messageText);
bottom.add(send);
add(bottom, BorderLayout.SOUTH);
addListeners();
setLocationRelativeTo(null);
setVisible(true);
ChatServer.getState(topLabel, chatingText);
}
private void addListeners(){
itemExit.addActionListener(e -> {
ChatServer.getState(topLabel, chatingText).exit();
dispose();
});
itemServerHost.addActionListener(e -> {
topLabel.setText(JOptionPane.showInputDialog(this, "Введите ip-адрес сервера"));
});
send.addActionListener(e -> {
String message = messageText.getText();
ChatServer.getState(topLabel, chatingText).sendMessage(message);
});
}
private void getSettings(){
serverHost = ClientProperties.getState().getServerHost();
serverPort = ClientProperties.getState().getServerPort();
username = ClientProperties.getState().getUsername();
}
}

73
java/samples/tcp/Chat/ChatClientJ130_lesson4_group1/src/chatclientj130_lesson4_group1/ClientProperties.java

@ -0,0 +1,73 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package chatclientj130_lesson4_group1;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Paths;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author Denis
*/
public class ClientProperties {
private final Properties properties;
private final static ClientProperties propertyState = new ClientProperties();
private final File propertyFile;
private ClientProperties(){
properties = new Properties();
String path = Paths.get("").toAbsolutePath().toString() + File.separator + "client.property";
propertyFile = new File(path);
try {
if(!propertyFile.exists()){
propertyFile.createNewFile();
}
} catch (IOException ex) {
Logger.getLogger(ClientProperties.class.getName()).log(Level.SEVERE, null, ex);
}
}
public final static ClientProperties getState(){
return propertyState;
}
public String getServerHost(){
try {properties.load(new FileReader(propertyFile));} catch (IOException ex) {}
return properties.getProperty("host", "188.134.85.87");
}
public int getServerPort(){
try {properties.load(new FileReader(propertyFile));} catch (IOException ex) {}
String port = properties.getProperty("port", "8092");
return port.matches("\\d+") ? Integer.valueOf(port) : 7007;
}
public String getUsername(){
try {properties.load(new FileReader(propertyFile));} catch (IOException ex) {}
return properties.getProperty("username");
}
public void setServerHost(String severHost){
properties.setProperty("host", severHost);
try {properties.store(new FileWriter(propertyFile), null);} catch (IOException ex) {}
}
public void setServerPort(String severPort){
properties.setProperty("port", severPort);
try {properties.store(new FileWriter(propertyFile), null);} catch (IOException ex) {}
}
public void setUsername(String username){
properties.setProperty("username", username);
try {properties.store(new FileWriter(propertyFile), null);} catch (IOException ex) {}
}
}

21
java/samples/tcp/Chat/ChatClientJ130_lesson4_group1/src/chatclientj130_lesson4_group1/MainClass.java

@ -0,0 +1,21 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package chatclientj130_lesson4_group1;
/**
*
* @author Denis
*/
public class MainClass {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
new ClientFrame();
}
}

73
java/samples/tcp/Chat/ChatServerJ130_lesson4_group1/build.xml

@ -0,0 +1,73 @@
<?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="ChatServerJ130_lesson4_group1" default="default" basedir=".">
<description>Builds, tests, and runs the project ChatServerJ130_lesson4_group1.</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: JAR building
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="ChatServerJ130_lesson4_group1-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>

4
java/samples/tcp/Chat/ChatServerJ130_lesson4_group1/build/built-jar.properties

@ -0,0 +1,4 @@
#Wed, 25 Jan 2023 21:19:31 +0300
C\:\\Users\\denis.LAPTOP-4LI8UQ4O\\OneDrive\\\u0414\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b\\NetBeansProjects\\ChatServerJ130_lesson4_group1=

BIN
java/samples/tcp/Chat/ChatServerJ130_lesson4_group1/build/classes/chatserverj130_lesson4_group1/ClientSocket.class

Binary file not shown.

BIN
java/samples/tcp/Chat/ChatServerJ130_lesson4_group1/build/classes/chatserverj130_lesson4_group1/MainClass.class

Binary file not shown.

BIN
java/samples/tcp/Chat/ChatServerJ130_lesson4_group1/build/classes/chatserverj130_lesson4_group1/Message.class

Binary file not shown.

BIN
java/samples/tcp/Chat/ChatServerJ130_lesson4_group1/build/classes/chatserverj130_lesson4_group1/MessageStore.class

Binary file not shown.

BIN
java/samples/tcp/Chat/ChatServerJ130_lesson4_group1/build/classes/chatserverj130_lesson4_group1/PortListener.class

Binary file not shown.

BIN
java/samples/tcp/Chat/ChatServerJ130_lesson4_group1/dist/ChatServerJ130_lesson4_group1.jar vendored

Binary file not shown.

32
java/samples/tcp/Chat/ChatServerJ130_lesson4_group1/dist/README.TXT vendored

@ -0,0 +1,32 @@
========================
BUILD OUTPUT DESCRIPTION
========================
When you build an Java application project that has a main class, the IDE
automatically copies all of the JAR
files on the projects classpath to your projects dist/lib folder. The IDE
also adds each of the JAR files to the Class-Path element in the application
JAR files manifest file (MANIFEST.MF).
To run the project from the command line, go to the dist folder and
type the following:
java -jar "ChatServerJ130_lesson4_group1.jar"
To distribute this project, zip up the dist folder (including the lib folder)
and distribute the ZIP file.
Notes:
* If two JAR files on the project classpath have the same name, only the first
JAR file is copied to the lib folder.
* Only JAR files are copied to the lib folder.
If the classpath contains other types of files or folders, these files (folders)
are not copied.
* If a library on the projects classpath also has a Class-Path element
specified in the manifest,the content of the Class-Path element has to be on
the projects runtime path.
* To set a main class in a standard Java project, right-click the project node
in the Projects window and choose Properties. Then click Run and enter the
class name in the Main Class field. Alternatively, you can manually type the
class name in the manifest Main-Class element.

3
java/samples/tcp/Chat/ChatServerJ130_lesson4_group1/manifest.mf

@ -0,0 +1,3 @@
Manifest-Version: 1.0
X-COMMENT: Main-Class will be added automatically by build

1420
java/samples/tcp/Chat/ChatServerJ130_lesson4_group1/nbproject/build-impl.xml

File diff suppressed because it is too large Load Diff

8
java/samples/tcp/Chat/ChatServerJ130_lesson4_group1/nbproject/genfiles.properties

@ -0,0 +1,8 @@
build.xml.data.CRC32=c2fa2be0
build.xml.script.CRC32=cf302020
build.xml.stylesheet.CRC32=8064a381@1.80.1.48
# 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=c2fa2be0
nbproject/build-impl.xml.script.CRC32=6be3a0a1
nbproject/build-impl.xml.stylesheet.CRC32=830a3534@1.80.1.48

2
java/samples/tcp/Chat/ChatServerJ130_lesson4_group1/nbproject/private/private.properties

@ -0,0 +1,2 @@
compile.on.save=true
user.properties.file=C:\\Users\\denis.LAPTOP-4LI8UQ4O\\AppData\\Roaming\\NetBeans\\8.2\\build.properties

10
java/samples/tcp/Chat/ChatServerJ130_lesson4_group1/nbproject/private/private.xml

@ -0,0 +1,10 @@
<?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/2" lastBookmarkId="0"/>
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group>
<file>file:/C:/Users/denis.LAPTOP-4LI8UQ4O/OneDrive/Документы/NetBeansProjects/ChatServerJ130_lesson4_group1/src/chatserverj130_lesson4_group1/ClientSocket.java</file>
<file>file:/C:/Users/denis.LAPTOP-4LI8UQ4O/OneDrive/Документы/NetBeansProjects/ChatServerJ130_lesson4_group1/src/chatserverj130_lesson4_group1/MainClass.java</file>
</group>
</open-files>
</project-private>

74
java/samples/tcp/Chat/ChatServerJ130_lesson4_group1/nbproject/project.properties

@ -0,0 +1,74 @@
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}
# \u0424\u0430\u0439\u043b\u044b \u0432 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0435 build.classes.dir, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0438\u0437 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u044f\u0435\u043c\u043e\u0433\u043e \u0430\u0440\u0445\u0438\u0432\u0430 jar
dist.archive.excludes=
# This directory is removed when the project is cleaned:
dist.dir=dist
dist.jar=${dist.dir}/ChatServerJ130_lesson4_group1.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.external.vm=true
javac.processorpath=\
${javac.classpath}
javac.source=1.8
javac.target=1.8
javac.test.classpath=\
${javac.classpath}:\
${build.classes.dir}
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=chatserverj130_lesson4_group1.MainClass
manifest.file=manifest.mf
meta.inf.dir=${src.dir}/META-INF
mkdist.disabled=false
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.
# To set system properties for unit tests define test-sys-prop.name=value:
run.jvmargs=
run.test.classpath=\
${javac.test.classpath}:\
${build.test.classes.dir}
source.encoding=UTF-8
src.dir=src
test.src.dir=test

15
java/samples/tcp/Chat/ChatServerJ130_lesson4_group1/nbproject/project.xml

@ -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>ChatServerJ130_lesson4_group1</name>
<source-roots>
<root id="src.dir"/>
</source-roots>
<test-roots>
<root id="test.src.dir"/>
</test-roots>
</data>
</configuration>
</project>

62
java/samples/tcp/Chat/ChatServerJ130_lesson4_group1/src/chatserverj130_lesson4_group1/ClientSocket.java

@ -0,0 +1,62 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package chatserverj130_lesson4_group1;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.net.Socket;
/**
*
* @author Denis
*/
public class ClientSocket {
public void client(Socket socket){
try(//BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
InputStream is = socket.getInputStream();
OutputStream os = socket.getOutputStream();){
byte[] buffer = new byte[1024];
int length;
StringBuilder sb = new StringBuilder();
while((length=is.read(buffer))>-1){
sb.append(new String(buffer, 0, length));
}
String message = sb.toString();
//String message = reader.readLine();
socket.shutdownInput();
int type = typeMessage(message);
if(type==1) {
String history = MessageStore.getState().getAllMessage();
buffer = history.getBytes();
os.write(buffer);
}
if(type==2) {
message = message.replace("post", "").trim();
MessageStore.addMessage(message);
buffer = "OK".getBytes();
os.write(buffer);
}
if(type==9) {
buffer = "ERROR".getBytes();
os.write(buffer);
}
}catch(IOException ioe){}
}
private int typeMessage(String message){
if(message!=null){
if(message.startsWith("get")) return 1;
if(message.startsWith("post")) return 2;
}
return 9;
}
}

25
java/samples/tcp/Chat/ChatServerJ130_lesson4_group1/src/chatserverj130_lesson4_group1/MainClass.java

@ -0,0 +1,25 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package chatserverj130_lesson4_group1;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author Denis
*/
public class MainClass {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
PortListener.startListener();
}
}

85
java/samples/tcp/Chat/ChatServerJ130_lesson4_group1/src/chatserverj130_lesson4_group1/Message.java

@ -0,0 +1,85 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package chatserverj130_lesson4_group1;
import java.util.Date;
import java.util.Objects;
/**
*
* @author Denis
*/
public class Message implements Comparable<Message>{
private String user;
private Date time;
private String text;
public String getUser() {
return user;
}
public Date getTime() {
return time;
}
public String getText() {
return text;
}
public void setUser(String user) {
this.user = user;
}
public void setTime(Date time) {
this.time = time;
}
public void setText(String text) {
this.text = text;
}
@Override
public int compareTo(Message o) {
return this.time.compareTo(o.time);
}
@Override
public int hashCode() {
int hash = 7;
hash = 11 * hash + Objects.hashCode(this.user);
hash = 11 * hash + Objects.hashCode(this.time);
hash = 11 * hash + Objects.hashCode(this.text);
return hash;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Message other = (Message) obj;
if (!Objects.equals(this.user, other.user)) {
return false;
}
if (!Objects.equals(this.text, other.text)) {
return false;
}
if (!Objects.equals(this.time, other.time)) {
return false;
}
return true;
}
}

49
java/samples/tcp/Chat/ChatServerJ130_lesson4_group1/src/chatserverj130_lesson4_group1/MessageStore.java

@ -0,0 +1,49 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package chatserverj130_lesson4_group1;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Set;
import java.util.TreeSet;
/**
*
* @author Denis
*/
public class MessageStore {
private static final MessageStore store = new MessageStore();
public Set<Message> mesages = new TreeSet<>();
private MessageStore(){}
public static MessageStore getState(){
return store;
}
public static boolean addMessage(String text){
Message mesObj = new Message();
String[] mes = text.split(">>");
if(mes.length<3) return false;
mesObj.setUser(mes[0].replace("get", "").trim());
mesObj.setTime(new Date(System.currentTimeMillis()));
mesObj.setText(mes[2].trim());
store.mesages.add(mesObj);
return true;
}
public String getAllMessage(){
SimpleDateFormat format = new SimpleDateFormat("yy.MM.dd hh:mm:ss");
StringBuilder sb = new StringBuilder();
mesages.forEach(message -> {
sb.append(message.getUser()).append(" >>> ")
.append(format.format(message.getTime()))
.append(" \n").append("\t")
.append(message.getText()).append("\n");
});
return sb.toString();
}
}

57
java/samples/tcp/Chat/ChatServerJ130_lesson4_group1/src/chatserverj130_lesson4_group1/PortListener.java

@ -0,0 +1,57 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package chatserverj130_lesson4_group1;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author Denis
*/
public final class PortListener implements Runnable{
private static PortListener portListener;
private static boolean stop;
private Thread thread;
private PortListener(){
stop = false;
thread = new Thread(portListener);
}
public static PortListener getState(){
return portListener;
}
public synchronized static void startListener(){
if(portListener==null) {
portListener = new PortListener();
portListener.thread = new Thread(portListener);
portListener.thread.start();
}
if(portListener.thread.getState().toString().equals("TERMINATED")){
portListener.thread = new Thread(portListener);
portListener.thread.start();
}
}
@Override
public void run() {
try (ServerSocket serverSocket = new ServerSocket(8092)) {
while(!stop){
Socket newSocket = serverSocket.accept();
new ClientSocket().client(newSocket);
}
} catch (IOException ex) {
Logger.getLogger(PortListener.class.getName()).log(Level.SEVERE, null, ex);
}
}
}

73
java/samples/tcp/Chat2/ChatClientJ130_lesson4_group2/build.xml

@ -0,0 +1,73 @@
<?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="ChatClientJ130_lesson4_group2" default="default" basedir=".">
<description>Builds, tests, and runs the project ChatClientJ130_lesson4_group2.</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: JAR building
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="ChatClientJ130_lesson4_group2-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>

4
java/samples/tcp/Chat2/ChatClientJ130_lesson4_group2/build/built-jar.properties

@ -0,0 +1,4 @@
#Fri, 27 Jan 2023 21:07:39 +0300
C\:\\Users\\denis.LAPTOP-4LI8UQ4O\\OneDrive\\\u0414\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b\\NetBeansProjects\\ChatClientJ130_lesson4_group2=

BIN
java/samples/tcp/Chat2/ChatClientJ130_lesson4_group2/build/classes/chatclientj130_lesson4_group2/ChatServer.class

Binary file not shown.

BIN
java/samples/tcp/Chat2/ChatClientJ130_lesson4_group2/build/classes/chatclientj130_lesson4_group2/ClientFrame.class

Binary file not shown.

BIN
java/samples/tcp/Chat2/ChatClientJ130_lesson4_group2/build/classes/chatclientj130_lesson4_group2/ClientProperties.class

Binary file not shown.

BIN
java/samples/tcp/Chat2/ChatClientJ130_lesson4_group2/build/classes/chatclientj130_lesson4_group2/MainClass.class

Binary file not shown.

2
java/samples/tcp/Chat2/ChatClientJ130_lesson4_group2/client.property

@ -0,0 +1,2 @@
#Fri Jan 27 20:09:17 MSK 2023
username=Denis

BIN
java/samples/tcp/Chat2/ChatClientJ130_lesson4_group2/dist/ChatClientJ130_lesson4_group2.jar vendored

Binary file not shown.

32
java/samples/tcp/Chat2/ChatClientJ130_lesson4_group2/dist/README.TXT vendored

@ -0,0 +1,32 @@
========================
BUILD OUTPUT DESCRIPTION
========================
When you build an Java application project that has a main class, the IDE
automatically copies all of the JAR
files on the projects classpath to your projects dist/lib folder. The IDE
also adds each of the JAR files to the Class-Path element in the application
JAR files manifest file (MANIFEST.MF).
To run the project from the command line, go to the dist folder and
type the following:
java -jar "ChatClientJ130_lesson4_group2.jar"
To distribute this project, zip up the dist folder (including the lib folder)
and distribute the ZIP file.
Notes:
* If two JAR files on the project classpath have the same name, only the first
JAR file is copied to the lib folder.
* Only JAR files are copied to the lib folder.
If the classpath contains other types of files or folders, these files (folders)
are not copied.
* If a library on the projects classpath also has a Class-Path element
specified in the manifest,the content of the Class-Path element has to be on
the projects runtime path.
* To set a main class in a standard Java project, right-click the project node
in the Projects window and choose Properties. Then click Run and enter the
class name in the Main Class field. Alternatively, you can manually type the
class name in the manifest Main-Class element.

3
java/samples/tcp/Chat2/ChatClientJ130_lesson4_group2/manifest.mf

@ -0,0 +1,3 @@
Manifest-Version: 1.0
X-COMMENT: Main-Class will be added automatically by build

1420
java/samples/tcp/Chat2/ChatClientJ130_lesson4_group2/nbproject/build-impl.xml

File diff suppressed because it is too large Load Diff

8
java/samples/tcp/Chat2/ChatClientJ130_lesson4_group2/nbproject/genfiles.properties

@ -0,0 +1,8 @@
build.xml.data.CRC32=19595f86
build.xml.script.CRC32=2b14b91d
build.xml.stylesheet.CRC32=8064a381@1.80.1.48
# 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=19595f86
nbproject/build-impl.xml.script.CRC32=eb95a494
nbproject/build-impl.xml.stylesheet.CRC32=830a3534@1.80.1.48

2
java/samples/tcp/Chat2/ChatClientJ130_lesson4_group2/nbproject/private/private.properties

@ -0,0 +1,2 @@
compile.on.save=true
user.properties.file=C:\\Users\\denis.LAPTOP-4LI8UQ4O\\AppData\\Roaming\\NetBeans\\8.2\\build.properties

74
java/samples/tcp/Chat2/ChatClientJ130_lesson4_group2/nbproject/project.properties

@ -0,0 +1,74 @@
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}
# \u0424\u0430\u0439\u043b\u044b \u0432 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0435 build.classes.dir, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0438\u0437 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u044f\u0435\u043c\u043e\u0433\u043e \u0430\u0440\u0445\u0438\u0432\u0430 jar
dist.archive.excludes=
# This directory is removed when the project is cleaned:
dist.dir=dist
dist.jar=${dist.dir}/ChatClientJ130_lesson4_group2.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.external.vm=true
javac.processorpath=\
${javac.classpath}
javac.source=1.8
javac.target=1.8
javac.test.classpath=\
${javac.classpath}:\
${build.classes.dir}
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=chatclientj130_lesson4_group2.MainClass
manifest.file=manifest.mf
meta.inf.dir=${src.dir}/META-INF
mkdist.disabled=false
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.
# To set system properties for unit tests define test-sys-prop.name=value:
run.jvmargs=
run.test.classpath=\
${javac.test.classpath}:\
${build.test.classes.dir}
source.encoding=UTF-8
src.dir=src
test.src.dir=test

15
java/samples/tcp/Chat2/ChatClientJ130_lesson4_group2/nbproject/project.xml

@ -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>ChatClientJ130_lesson4_group2</name>
<source-roots>
<root id="src.dir"/>
</source-roots>
<test-roots>
<root id="test.src.dir"/>
</test-roots>
</data>
</configuration>
</project>

111
java/samples/tcp/Chat2/ChatClientJ130_lesson4_group2/src/chatclientj130_lesson4_group2/ChatServer.java

@ -0,0 +1,111 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package chatclientj130_lesson4_group2;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.Socket;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JLabel;
import javax.swing.JTextArea;
/**
*
* @author Denis
*/
public class ChatServer implements Runnable{
private static ChatServer chatServer;
private boolean isExit = false;
private JLabel topLabel;
private JTextArea chatingText;
private ChatServer(JLabel topLabel, JTextArea chatingText){
this.chatingText = chatingText;
this.topLabel = topLabel;
}
public static ChatServer getState(JLabel topLabel, JTextArea chatingText){
Thread thread = null;
if(chatServer==null) {
chatServer = new ChatServer(topLabel, chatingText);
thread = new Thread(chatServer);
thread.start();
}
if(thread!=null && thread.getState().toString().equals("TERMINATED")){
thread = new Thread(chatServer);
thread.start();
}
return chatServer;
}
@Override
public void run() {
while(!isExit){
updateChat();
try {Thread.sleep(1000);} catch (InterruptedException ex) {}
}
}
private void updateChat(){
try (Socket socket = new Socket(ClientProperties.getState().getServerHost(), ClientProperties.getState().getServerPort());
BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));){
String labelText = topLabel.getText();
if(socket.isConnected()) topLabel.setText("<html><font color='green'>" + labelText + "</font></html>");
writer.write("get messages" + "\n");
writer.flush();
StringBuilder sb = new StringBuilder();
String temp;
while((temp = reader.readLine())!=null){
sb.append(temp).append("\n");
}
chatingText.setText(sb.toString());
} catch (IOException ex) {
String labelText = topLabel.getText();
topLabel.setText("<html><font color='red'>" + labelText + "</font></html>");
Logger.getLogger(MainClass.class.getName()).log(Level.SEVERE, null, ex);
}
}
public void sendMessage(String message){
String username = ClientProperties.getState().getUsername();
message = "post" + username + " >> " + getCurrentTime() + " >> " + message;
try (Socket socket = new Socket(ClientProperties.getState().getServerHost(), ClientProperties.getState().getServerPort());
BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));){
String labelText = topLabel.getText();
if(socket.isConnected()) topLabel.setText("<html><font color='green'>" + labelText + "</font></html>");
writer.write(message + "\n");
writer.flush();
String answer = reader.readLine();
//chatingText.append(answer + System.lineSeparator());
reader.close();
writer.close();
} catch (IOException ex) {
String labelText = topLabel.getText();
topLabel.setText("<html><font color='red'>" + labelText + "</font></html>");
Logger.getLogger(MainClass.class.getName()).log(Level.SEVERE, null, ex);
}
}
private String getCurrentTime(){
Date currentDate = new Date(System.currentTimeMillis());
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy:MM:dd hh:mm:ss");
String time = dateFormat.format(currentDate);
return time;
}
public void exit(){
isExit = true;
}
}

92
java/samples/tcp/Chat2/ChatClientJ130_lesson4_group2/src/chatclientj130_lesson4_group2/ClientFrame.java

@ -0,0 +1,92 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package chatclientj130_lesson4_group2;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import javax.swing.*;
/**
*
* @author Denis
*/
public class ClientFrame extends JFrame{
private final JMenuBar menuBar;
private final JMenu menu;
private final JMenuItem itemExit;
private final JMenuItem itemServerHost;
private final JButton send;
private final JTextField messageText;
private final JTextArea chatingText;
private final JLabel topLabel;
private String serverHost;
private int serverPort;
private String username;
public ClientFrame(){
super("Chat client");
setSize(500, 700);
setDefaultCloseOperation(EXIT_ON_CLOSE);
getSettings();
setLayout(new BorderLayout());
topLabel = new JLabel(serverHost + ":" + serverPort + " >>> " + username);
if(username==null) {
ClientProperties.getState().setUsername(JOptionPane.showInputDialog(this, "Введите имя пользователя"));
getSettings();
topLabel.setText(serverHost + ":" + serverPort + " >>> " + username);
}
menuBar = new JMenuBar();
menu = new JMenu("File");
itemExit = new JMenuItem("Exit");
itemServerHost = new JMenuItem("Server settings");
setJMenuBar(menuBar);
menuBar.add(menu);
menu.add(itemExit);
menu.add(itemServerHost);
chatingText = new JTextArea();
messageText = new JTextField(" ");
send = new JButton("Send");
add(topLabel, BorderLayout.NORTH);
chatingText.setEditable(false);
add(chatingText, BorderLayout.CENTER);
messageText.setColumns(30);
JPanel bottom = new JPanel(new FlowLayout());
bottom.add(messageText);
bottom.add(send);
add(bottom, BorderLayout.SOUTH);
addListeners();
setLocationRelativeTo(null);
setVisible(true);
}
private void addListeners(){
itemExit.addActionListener(e -> {
ChatServer.getState(topLabel, chatingText).exit();
dispose();
});
itemServerHost.addActionListener(e -> {
topLabel.setText(JOptionPane.showInputDialog(this, "Введите ip-адрес сервера"));
});
send.addActionListener(e -> {
String message = messageText.getText();
ChatServer.getState(topLabel, chatingText).sendMessage(message);
});
}
private void getSettings(){
serverHost = ClientProperties.getState().getServerHost();
serverPort = ClientProperties.getState().getServerPort();
username = ClientProperties.getState().getUsername();
}
}

73
java/samples/tcp/Chat2/ChatClientJ130_lesson4_group2/src/chatclientj130_lesson4_group2/ClientProperties.java

@ -0,0 +1,73 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package chatclientj130_lesson4_group2;
import java.io.File;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.nio.file.Paths;
import java.util.Properties;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author Denis
*/
public class ClientProperties {
private final Properties properties;
private final static ClientProperties propertyState = new ClientProperties();
private final File propertyFile;
private ClientProperties(){
properties = new Properties();
String path = Paths.get("").toAbsolutePath().toString() + File.separator + "client.property";
propertyFile = new File(path);
try {
if(!propertyFile.exists()){
propertyFile.createNewFile();
}
} catch (IOException ex) {
Logger.getLogger(ClientProperties.class.getName()).log(Level.SEVERE, null, ex);
}
}
public final static ClientProperties getState(){
return propertyState;
}
public String getServerHost(){
try {properties.load(new FileReader(propertyFile));} catch (IOException ex) {}
return properties.getProperty("host", "188.134.85.87");
}
public int getServerPort(){
try {properties.load(new FileReader(propertyFile));} catch (IOException ex) {}
String port = properties.getProperty("port", "8092");
return port.matches("\\d+") ? Integer.valueOf(port) : 7007;
}
public String getUsername(){
try {properties.load(new FileReader(propertyFile));} catch (IOException ex) {}
return properties.getProperty("username");
}
public void setServerHost(String severHost){
properties.setProperty("host", severHost);
try {properties.store(new FileWriter(propertyFile), null);} catch (IOException ex) {}
}
public void setServerPort(String severPort){
properties.setProperty("port", severPort);
try {properties.store(new FileWriter(propertyFile), null);} catch (IOException ex) {}
}
public void setUsername(String username){
properties.setProperty("username", username);
try {properties.store(new FileWriter(propertyFile), null);} catch (IOException ex) {}
}
}

21
java/samples/tcp/Chat2/ChatClientJ130_lesson4_group2/src/chatclientj130_lesson4_group2/MainClass.java

@ -0,0 +1,21 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package chatclientj130_lesson4_group2;
/**
*
* @author Denis
*/
public class MainClass {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
new ClientFrame();
}
}

73
java/samples/tcp/Chat2/ChatServerJ130_lesson4_group2/build.xml

@ -0,0 +1,73 @@
<?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="ChatServerJ130_lesson4_group2" default="default" basedir=".">
<description>Builds, tests, and runs the project ChatServerJ130_lesson4_group2.</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: JAR building
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="ChatServerJ130_lesson4_group2-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>

4
java/samples/tcp/Chat2/ChatServerJ130_lesson4_group2/build/built-jar.properties

@ -0,0 +1,4 @@
#Fri, 27 Jan 2023 20:58:17 +0300
C\:\\Users\\denis.LAPTOP-4LI8UQ4O\\OneDrive\\\u0414\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b\\NetBeansProjects\\ChatServerJ130_lesson4_group2=

BIN
java/samples/tcp/Chat2/ChatServerJ130_lesson4_group2/build/classes/chatserverj130_lesson4_group2/ClientSocket.class

Binary file not shown.

BIN
java/samples/tcp/Chat2/ChatServerJ130_lesson4_group2/build/classes/chatserverj130_lesson4_group2/MainClass.class

Binary file not shown.

BIN
java/samples/tcp/Chat2/ChatServerJ130_lesson4_group2/build/classes/chatserverj130_lesson4_group2/Message.class

Binary file not shown.

BIN
java/samples/tcp/Chat2/ChatServerJ130_lesson4_group2/build/classes/chatserverj130_lesson4_group2/MessageStore.class

Binary file not shown.

BIN
java/samples/tcp/Chat2/ChatServerJ130_lesson4_group2/build/classes/chatserverj130_lesson4_group2/PortListener.class

Binary file not shown.

BIN
java/samples/tcp/Chat2/ChatServerJ130_lesson4_group2/dist/ChatServerJ130_lesson4_group2.jar vendored

Binary file not shown.

32
java/samples/tcp/Chat2/ChatServerJ130_lesson4_group2/dist/README.TXT vendored

@ -0,0 +1,32 @@
========================
BUILD OUTPUT DESCRIPTION
========================
When you build an Java application project that has a main class, the IDE
automatically copies all of the JAR
files on the projects classpath to your projects dist/lib folder. The IDE
also adds each of the JAR files to the Class-Path element in the application
JAR files manifest file (MANIFEST.MF).
To run the project from the command line, go to the dist folder and
type the following:
java -jar "ChatServerJ130_lesson4_group2.jar"
To distribute this project, zip up the dist folder (including the lib folder)
and distribute the ZIP file.
Notes:
* If two JAR files on the project classpath have the same name, only the first
JAR file is copied to the lib folder.
* Only JAR files are copied to the lib folder.
If the classpath contains other types of files or folders, these files (folders)
are not copied.
* If a library on the projects classpath also has a Class-Path element
specified in the manifest,the content of the Class-Path element has to be on
the projects runtime path.
* To set a main class in a standard Java project, right-click the project node
in the Projects window and choose Properties. Then click Run and enter the
class name in the Main Class field. Alternatively, you can manually type the
class name in the manifest Main-Class element.

3
java/samples/tcp/Chat2/ChatServerJ130_lesson4_group2/manifest.mf

@ -0,0 +1,3 @@
Manifest-Version: 1.0
X-COMMENT: Main-Class will be added automatically by build

1420
java/samples/tcp/Chat2/ChatServerJ130_lesson4_group2/nbproject/build-impl.xml

File diff suppressed because it is too large Load Diff

8
java/samples/tcp/Chat2/ChatServerJ130_lesson4_group2/nbproject/genfiles.properties

@ -0,0 +1,8 @@
build.xml.data.CRC32=dacebf8a
build.xml.script.CRC32=78491380
build.xml.stylesheet.CRC32=8064a381@1.80.1.48
# 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=dacebf8a
nbproject/build-impl.xml.script.CRC32=d1670449
nbproject/build-impl.xml.stylesheet.CRC32=830a3534@1.80.1.48

2
java/samples/tcp/Chat2/ChatServerJ130_lesson4_group2/nbproject/private/private.properties

@ -0,0 +1,2 @@
compile.on.save=true
user.properties.file=C:\\Users\\denis.LAPTOP-4LI8UQ4O\\AppData\\Roaming\\NetBeans\\8.2\\build.properties

74
java/samples/tcp/Chat2/ChatServerJ130_lesson4_group2/nbproject/project.properties

@ -0,0 +1,74 @@
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}
# \u0424\u0430\u0439\u043b\u044b \u0432 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0435 build.classes.dir, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0438\u0437 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u044f\u0435\u043c\u043e\u0433\u043e \u0430\u0440\u0445\u0438\u0432\u0430 jar
dist.archive.excludes=
# This directory is removed when the project is cleaned:
dist.dir=dist
dist.jar=${dist.dir}/ChatServerJ130_lesson4_group2.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.external.vm=true
javac.processorpath=\
${javac.classpath}
javac.source=1.8
javac.target=1.8
javac.test.classpath=\
${javac.classpath}:\
${build.classes.dir}
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=chatserverj130_lesson4_group2.MainClass
manifest.file=manifest.mf
meta.inf.dir=${src.dir}/META-INF
mkdist.disabled=false
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.
# To set system properties for unit tests define test-sys-prop.name=value:
run.jvmargs=
run.test.classpath=\
${javac.test.classpath}:\
${build.test.classes.dir}
source.encoding=UTF-8
src.dir=src
test.src.dir=test

15
java/samples/tcp/Chat2/ChatServerJ130_lesson4_group2/nbproject/project.xml

@ -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>ChatServerJ130_lesson4_group2</name>
<source-roots>
<root id="src.dir"/>
</source-roots>
<test-roots>
<root id="test.src.dir"/>
</test-roots>
</data>
</configuration>
</project>

42
java/samples/tcp/Chat2/ChatServerJ130_lesson4_group2/src/chatserverj130_lesson4_group2/ClientSocket.java

@ -0,0 +1,42 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package chatserverj130_lesson4_group2;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.Socket;
/**
*
* @author Denis
*/
public class ClientSocket {
public void client(Socket socket){
try(BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));){
String message = reader.readLine();
int type = typeMessage(message);
if(type==1) writer.write(MessageStore.getState().getAllMessage());
if(type==2) {
message = message.replace("post", "").trim();
MessageStore.addMessage(message);
writer.write("OK");
}
if(type==9) writer.write("ERROR");
writer.flush();
}catch(IOException ioe){}
}
private int typeMessage(String message){
if(message.startsWith("get")) return 1;
if(message.startsWith("post")) return 2;
return 9;
}
}

34
java/samples/tcp/Chat2/ChatServerJ130_lesson4_group2/src/chatserverj130_lesson4_group2/MainClass.java

@ -0,0 +1,34 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package chatserverj130_lesson4_group2;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author Denis
*/
public class MainClass {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// PortListener listener = PortListener.getState();
// Thread thread = new Thread(listener);
// thread.start();
PortListener.startListener();
try {
Thread.sleep(3000);
} catch (InterruptedException ex) {
Logger.getLogger(MainClass.class.getName()).log(Level.SEVERE, null, ex);
}
PortListener.startListener();
}
}

85
java/samples/tcp/Chat2/ChatServerJ130_lesson4_group2/src/chatserverj130_lesson4_group2/Message.java

@ -0,0 +1,85 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package chatserverj130_lesson4_group2;
import java.util.Date;
import java.util.Objects;
/**
*
* @author Denis
*/
public class Message implements Comparable<Message>{
private String user;
private Date time;
private String text;
public String getUser() {
return user;
}
public Date getTime() {
return time;
}
public String getText() {
return text;
}
public void setUser(String user) {
this.user = user;
}
public void setTime(Date time) {
this.time = time;
}
public void setText(String text) {
this.text = text;
}
@Override
public int compareTo(Message o) {
return this.time.compareTo(o.time);
}
@Override
public int hashCode() {
int hash = 7;
hash = 11 * hash + Objects.hashCode(this.user);
hash = 11 * hash + Objects.hashCode(this.time);
hash = 11 * hash + Objects.hashCode(this.text);
return hash;
}
@Override
public boolean equals(Object obj) {
if (this == obj) {
return true;
}
if (obj == null) {
return false;
}
if (getClass() != obj.getClass()) {
return false;
}
final Message other = (Message) obj;
if (!Objects.equals(this.user, other.user)) {
return false;
}
if (!Objects.equals(this.text, other.text)) {
return false;
}
if (!Objects.equals(this.time, other.time)) {
return false;
}
return true;
}
}

48
java/samples/tcp/Chat2/ChatServerJ130_lesson4_group2/src/chatserverj130_lesson4_group2/MessageStore.java

@ -0,0 +1,48 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package chatserverj130_lesson4_group2;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Set;
import java.util.TreeSet;
/**
*
* @author Denis
*/
public class MessageStore {
private static final MessageStore store = new MessageStore();
public Set<Message> mesages = new TreeSet<>();
private MessageStore(){}
public static MessageStore getState(){
return store;
}
public static boolean addMessage(String text){
Message mesObj = new Message();
String[] mes = text.split(">>");
if(mes.length<3) return false;
mesObj.setUser(mes[0].replace("get", "").trim());
mesObj.setTime(new Date(System.currentTimeMillis()));
mesObj.setText(mes[2].trim());
store.mesages.add(mesObj);
return true;
}
public String getAllMessage(){
SimpleDateFormat format = new SimpleDateFormat("yy.MM.dd HH:mm:ss");
StringBuilder sb = new StringBuilder();
mesages.forEach(message -> {
sb.append(message.getUser()).append(" >>> ")
.append(format.format(message.getTime())).append(" >>> \n\t")
.append(message.getText()).append("\n");
});
return sb.toString();
}
}

52
java/samples/tcp/Chat2/ChatServerJ130_lesson4_group2/src/chatserverj130_lesson4_group2/PortListener.java

@ -0,0 +1,52 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package chatserverj130_lesson4_group2;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author Denis
*/
public final class PortListener implements Runnable{
private static PortListener portListener;
private static boolean stop;
private Thread thread;
private PortListener(){
stop = false;
thread = new Thread(portListener);
}
public synchronized final static void startListener(){
if(portListener==null) {
portListener = new PortListener();
portListener.thread = new Thread(portListener);
portListener.thread.start();
}
if(portListener.thread.getState().toString().equals("TERMINATED")){
portListener.thread = new Thread(portListener);
portListener.thread.start();
}
}
@Override
public void run() {
try (ServerSocket serverSocket = new ServerSocket(8092)) {
while(!stop){
Socket newSocket = serverSocket.accept();
new ClientSocket().client(newSocket);
}
} catch (IOException ex) {
Logger.getLogger(PortListener.class.getName()).log(Level.SEVERE, null, ex);
}
}
}

73
java/samples/tcp/NetworkTransfer/NetworkTransferClient/build.xml

@ -0,0 +1,73 @@
<?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="NetworkTransferClient" default="default" basedir=".">
<description>Builds, tests, and runs the project NetworkTransferClient.</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: JAR building
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="NetworkTransferClient-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>

0
java/samples/tcp/NetworkTransfer/NetworkTransferClient/build/classes/.netbeans_automatic_build

0
java/samples/tcp/NetworkTransfer/NetworkTransferClient/build/classes/.netbeans_update_resources

BIN
java/samples/tcp/NetworkTransfer/NetworkTransferClient/build/classes/networktransferclient/NetworkTransferClient.class

Binary file not shown.

BIN
java/samples/tcp/NetworkTransfer/NetworkTransferClient/j130-lab1.pdf

Binary file not shown.

BIN
java/samples/tcp/NetworkTransfer/NetworkTransferClient/j130-lab2-2.pdf

Binary file not shown.

BIN
java/samples/tcp/NetworkTransfer/NetworkTransferClient/j130-lab2.pdf

Binary file not shown.

BIN
java/samples/tcp/NetworkTransfer/NetworkTransferClient/j130-lab3.pdf

Binary file not shown.

BIN
java/samples/tcp/NetworkTransfer/NetworkTransferClient/j130-lab4.pdf

Binary file not shown.

3
java/samples/tcp/NetworkTransfer/NetworkTransferClient/manifest.mf

@ -0,0 +1,3 @@
Manifest-Version: 1.0
X-COMMENT: Main-Class will be added automatically by build

1420
java/samples/tcp/NetworkTransfer/NetworkTransferClient/nbproject/build-impl.xml

File diff suppressed because it is too large Load Diff

8
java/samples/tcp/NetworkTransfer/NetworkTransferClient/nbproject/genfiles.properties

@ -0,0 +1,8 @@
build.xml.data.CRC32=29cf46d3
build.xml.script.CRC32=b109d07b
build.xml.stylesheet.CRC32=8064a381@1.80.1.48
# 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=29cf46d3
nbproject/build-impl.xml.script.CRC32=bd8087d6
nbproject/build-impl.xml.stylesheet.CRC32=830a3534@1.80.1.48

2
java/samples/tcp/NetworkTransfer/NetworkTransferClient/nbproject/private/private.properties

@ -0,0 +1,2 @@
compile.on.save=true
user.properties.file=C:\\Users\\denis.LAPTOP-4LI8UQ4O\\AppData\\Roaming\\NetBeans\\8.2\\build.properties

74
java/samples/tcp/NetworkTransfer/NetworkTransferClient/nbproject/project.properties

@ -0,0 +1,74 @@
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}
# \u0424\u0430\u0439\u043b\u044b \u0432 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0435 build.classes.dir, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u044c \u0438\u0437 \u0440\u0430\u0441\u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u044f\u0435\u043c\u043e\u0433\u043e \u0430\u0440\u0445\u0438\u0432\u0430 jar
dist.archive.excludes=
# This directory is removed when the project is cleaned:
dist.dir=dist
dist.jar=${dist.dir}/NetworkTransferClient.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.external.vm=true
javac.processorpath=\
${javac.classpath}
javac.source=1.8
javac.target=1.8
javac.test.classpath=\
${javac.classpath}:\
${build.classes.dir}
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=networktransferclient.NetworkTransferClient
manifest.file=manifest.mf
meta.inf.dir=${src.dir}/META-INF
mkdist.disabled=false
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.
# To set system properties for unit tests define test-sys-prop.name=value:
run.jvmargs=
run.test.classpath=\
${javac.test.classpath}:\
${build.test.classes.dir}
source.encoding=UTF-8
src.dir=src
test.src.dir=test

15
java/samples/tcp/NetworkTransfer/NetworkTransferClient/nbproject/project.xml

@ -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>NetworkTransferClient</name>
<source-roots>
<root id="src.dir"/>
</source-roots>
<test-roots>
<root id="test.src.dir"/>
</test-roots>
</data>
</configuration>
</project>

52
java/samples/tcp/NetworkTransfer/NetworkTransferClient/src/networktransferclient/NetworkTransferClient.java

@ -0,0 +1,52 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package networktransferclient;
import java.io.BufferedInputStream;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Socket;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
*
* @author denis
*/
public class NetworkTransferClient {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
try ( Socket socket = new Socket("127.0.0.1", 15001);
DataOutputStream dataOutputStream = new DataOutputStream(socket.getOutputStream());
BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()));){
File file = new File("j130-lab2.pdf");
if(file.exists()) {
dataOutputStream.writeUTF(file.getName());
byte[] buffer = new byte[1024];
try(FileInputStream fis = new FileInputStream(file)){
int length;
while((length=fis.read(buffer))>-1){
dataOutputStream.write(buffer, 0, length);
}
}
socket.shutdownOutput();
String msg = reader.readLine();
System.out.println("Получен ответ от сервера: " + msg);
}
} catch (IOException ex) {
Logger.getLogger(NetworkTransferClient.class.getName()).log(Level.SEVERE, null, ex);
}
}
}

73
java/samples/tcp/NetworkTransfer/NetworkTransferServer/build.xml

@ -0,0 +1,73 @@
<?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="NetworkTransferServer" default="default" basedir=".">
<description>Builds, tests, and runs the project NetworkTransferServer.</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: JAR building
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="NetworkTransferServer-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>

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save