Compare commits

..

1 Commits
0.0.1 ... main

Author SHA1 Message Date
lensfrex 5aefe4a893
更新部分代码 2 years ago
  1. 2
      .run/1.3 AbstractExtends.run.xml
  2. 24
      exp1-oop/pom.xml
  3. 16
      exp1-oop/src/main/java/net/lensfrex/AbstractExtends.java
  4. 24
      exp2-thread/pom.xml
  5. 20
      exp3-network/pom.xml
  6. 3
      exp3-network/src/main/java/net/lensfrex/socket/client/Client.java
  7. 6
      exp3-network/src/main/java/net/lensfrex/socket/server/Server.java
  8. 24
      pom.xml

@ -1,7 +1,7 @@
<component name="ProjectRunConfigurationManager"> <component name="ProjectRunConfigurationManager">
<configuration default="false" name="1.3 AbstractExtends" type="Application" factoryName="Application"> <configuration default="false" name="1.3 AbstractExtends" type="Application" factoryName="Application">
<option name="MAIN_CLASS_NAME" value="net.lensfrex.Main" /> <option name="MAIN_CLASS_NAME" value="net.lensfrex.Main" />
<module name="exp3-network" /> <module name="exp1-oop" />
<option name="PROGRAM_PARAMETERS" value="3" /> <option name="PROGRAM_PARAMETERS" value="3" />
<extension name="coverage"> <extension name="coverage">
<pattern> <pattern>

@ -17,4 +17,28 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> </properties>
<build>
<finalName>exp1-oop</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>net.lensfrex.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project> </project>

@ -6,6 +6,22 @@ public class AbstractExtends {
father.method1(); father.method1();
father.method2(); father.method2();
// 匿名类的方式实现
Father father1 = new Father() {
@Override
public void method1() {
System.out.println("Do some thing in method1");
}
@Override
public void method2() {
System.out.println("Do some thing in method2");
}
};
father1.method1();
father1.method2();
} }
} }

@ -17,4 +17,28 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> </properties>
<build>
<finalName>exp2-thread</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>net.lensfrex.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project> </project>

@ -16,14 +16,9 @@
<maven.compiler.target>8</maven.compiler.target> <maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> </properties>
<dependencies>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.11.0</version>
</dependency>
</dependencies>
<build> <build>
<finalName>exp3-network</finalName>
<plugins> <plugins>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
@ -33,6 +28,17 @@
<target>1.8</target> <target>1.8</target>
</configuration> </configuration>
</plugin> </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>net.lensfrex.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins> </plugins>
</build> </build>

@ -113,7 +113,7 @@ class UI {
this.changeLoginStatus(true); this.changeLoginStatus(true);
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();
messageTextArea.textProperty().set("请求服务器时发生错误:" + ex); messageTextArea.textProperty().set(messageTextArea.getText() + "请求服务器时发生错误:" + ex);
} }
}); });
@ -167,6 +167,7 @@ class UI {
MessageData messageData = new MessageData(usernameTextField.getText(), messageTextField.getText()); MessageData messageData = new MessageData(usernameTextField.getText(), messageTextField.getText());
DataPack responseDataPack = this.sendData(messageData.toBytes(), Constant.OPCODE_SEND_MESSAGE); DataPack responseDataPack = this.sendData(messageData.toBytes(), Constant.OPCODE_SEND_MESSAGE);
messageTextField.textProperty().set("");
this.displayResponse(responseDataPack); this.displayResponse(responseDataPack);
} catch (Exception ex) { } catch (Exception ex) {
ex.printStackTrace(); ex.printStackTrace();

@ -42,6 +42,8 @@ class ServerThread extends Thread {
@Override @Override
public void run() { public void run() {
System.out.println("New thread started.");
try (InputStream inputStream = socket.getInputStream(); OutputStream outputStream = socket.getOutputStream()) { try (InputStream inputStream = socket.getInputStream(); OutputStream outputStream = socket.getOutputStream()) {
byte[] clientMagicHeader = new byte[Constant.MAGIC_HEADER.length]; byte[] clientMagicHeader = new byte[Constant.MAGIC_HEADER.length];
if (inputStream.read(clientMagicHeader) == -1) { if (inputStream.read(clientMagicHeader) == -1) {
@ -64,15 +66,17 @@ class ServerThread extends Thread {
if (Arrays.equals(Constant.OPCODE_LOGIN, opcode)) { if (Arrays.equals(Constant.OPCODE_LOGIN, opcode)) {
this.login(new String(dataPack.getData())); this.login(new String(dataPack.getData()));
Common.writeMessage(SERVER_ID, Constant.MESSAGE_OK, outputStream); Common.writeMessage(SERVER_ID, Constant.MESSAGE_OK, outputStream);
} else if (Arrays.equals(Constant.OPCODE_LOGOUT, opcode)) { } else if (Arrays.equals(Constant.OPCODE_LOGOUT, opcode)) {
this.logout(new String(dataPack.getData())); this.logout(new String(dataPack.getData()));
Common.writeMessage(SERVER_ID, Constant.MESSAGE_OK, outputStream); Common.writeMessage(SERVER_ID, Constant.MESSAGE_OK, outputStream);
} else if (Arrays.equals(Constant.OPCODE_REQUEST_MESSAGE, opcode)) { } else if (Arrays.equals(Constant.OPCODE_REQUEST_MESSAGE, opcode)) {
this.sendRandomMessage(outputStream); this.sendRandomMessage(outputStream);
} else if (Arrays.equals(Constant.OPCODE_SEND_MESSAGE, opcode)) { } else if (Arrays.equals(Constant.OPCODE_SEND_MESSAGE, opcode)) {
String receivedMessage = this.receiveMessage(dataPack); String receivedMessage = this.receiveMessage(dataPack);
String responseMessage = String.format("Receive message '%s'", receivedMessage); String responseMessage = String.format("Receive message '%s'", receivedMessage);
Common.writeMessage(SERVER_ID, responseMessage, outputStream); Common.writeMessage(SERVER_ID, responseMessage, outputStream);
} }
} }

@ -19,5 +19,27 @@
<maven.compiler.target>8</maven.compiler.target> <maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties> </properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>net.lensfrex.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
</project> </project>
Loading…
Cancel
Save