更新部分代码

main
lensfrex 2 years ago
parent ef192fa2a4
commit 5aefe4a893
Signed by: lensfrex
GPG Key ID: 947ADABD8533C476
  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">
<configuration default="false" name="1.3 AbstractExtends" type="Application" factoryName="Application">
<option name="MAIN_CLASS_NAME" value="net.lensfrex.Main" />
<module name="exp3-network" />
<module name="exp1-oop" />
<option name="PROGRAM_PARAMETERS" value="3" />
<extension name="coverage">
<pattern>

@ -17,4 +17,28 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</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>

@ -6,6 +6,22 @@ public class AbstractExtends {
father.method1();
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>
</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>

@ -16,14 +16,9 @@
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.11.0</version>
</dependency>
</dependencies>
<build>
<finalName>exp3-network</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
@ -33,6 +28,17 @@
<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>

@ -113,7 +113,7 @@ class UI {
this.changeLoginStatus(true);
} catch (Exception ex) {
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());
DataPack responseDataPack = this.sendData(messageData.toBytes(), Constant.OPCODE_SEND_MESSAGE);
messageTextField.textProperty().set("");
this.displayResponse(responseDataPack);
} catch (Exception ex) {
ex.printStackTrace();

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

@ -19,5 +19,27 @@
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</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>
Loading…
Cancel
Save