Skip to content
This repository was archived by the owner on Aug 6, 2024. It is now read-only.

Commit 5653d64

Browse files
committed
test commit, this may fix our problem with pps
1 parent 29f21da commit 5653d64

File tree

5 files changed

+23
-10
lines changed

5 files changed

+23
-10
lines changed

build

100755100644
File mode changed.

pom.xml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,11 @@
2929
<artifactId>annotations</artifactId>
3030
<version>24.1.0</version>
3131
</dependency>
32-
<dependency>
32+
<dependency>
3333
<groupId>org.projectlombok</groupId>
3434
<artifactId>lombok</artifactId>
3535
<version>RELEASE</version>
36-
<scope>compile</scope>
37-
</dependency>
36+
</dependency>
3837
</dependencies>
3938
<build>
4039
<pluginManagement>

src/main/java/ir/xenoncommunity/MainRunner.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ public void run() {
2929
val isResult = Main.runner.parser.get("--sendResult", Boolean.class);
3030
val isKeepAlive = Main.runner.parser.get("--keepAlive", Boolean.class);
3131
val udp = Main.runner.parser.get("--udp", Boolean.class);
32+
val sendBytes = Main.runner.parser.get("--sendBytes", Boolean.class);
33+
val byteSize = Main.runner.parser.get("--byteSize", Integer.class);
3234
if(this.isDebug()){
3335
getLogger().setSection("DEBUG");
3436
getLogger().print(Logger.LEVEL.INFO, "ip is: " + ip);
@@ -37,13 +39,15 @@ public void run() {
3739
getLogger().print(Logger.LEVEL.INFO, "isResult is: " + isResult);
3840
getLogger().print(Logger.LEVEL.INFO, "isKeepAlive is: " + isKeepAlive);
3941
getLogger().print(Logger.LEVEL.INFO, "udp is: " + udp);
42+
getLogger().print(Logger.LEVEL.INFO, "sendBytes is: " + sendBytes);
43+
getLogger().print(Logger.LEVEL.INFO, "byteSize is: " + byteSize);
4044
}
4145
for(int i = 0; i <= maxThreads; i++){
4246
if(this.isDebug)
4347
getLogger().print(Logger.LEVEL.INFO, "adding new thread. max: " + maxThreads);
4448
getTaskManager().add(new Thread(() -> {
4549
while (true)
46-
socketUtils.connect(ip, port, isResult, isKeepAlive, udp);
50+
socketUtils.connect(ip, port, isResult, isKeepAlive, udp, sendBytes, byteSize);
4751
}));
4852
}
4953
getLogger().print(Logger.LEVEL.INFO, "doing tasks...");

src/main/java/ir/xenoncommunity/utils/SocketUtils.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@
33
import ir.xenoncommunity.Main;
44
import lombok.val;
55

6+
import java.io.DataOutputStream;
67
import java.net.DatagramSocket;
78
import java.net.InetAddress;
89
import java.net.Socket;
10+
import java.nio.ByteBuffer;
911

1012
public class SocketUtils {
11-
public void connect(final String ipAddress, final int port, final boolean sendResult, final boolean keepAlive, final boolean udp) {
13+
public void connect(final String ipAddress, final int port, final boolean sendResult, final boolean keepAlive, final boolean udp, final boolean writeBytes, final int byteSize) {
1214
Main.runner.getLogger().setSection("CONNECT");
1315
try {
1416
if (udp) {
@@ -17,18 +19,25 @@ public void connect(final String ipAddress, final int port, final boolean sendRe
1719
throw new IllegalStateException("UDP is used with keepAlive.");
1820
}
1921
try (val socket = new DatagramSocket(port, InetAddress.getByName(ipAddress))) {
20-
if (sendResult && socket.isConnected()) {
22+
if (sendResult && socket.isConnected())
2123
Main.runner.getLogger().print(Logger.LEVEL.INFO, String.format("Connected! ip: %s, port: %s, threads: %s\n", ipAddress, port, Main.runner.getTaskManager().tasks.size()));
22-
}
24+
25+
if(writeBytes)
26+
socket.getChannel().write(ByteBuffer.allocateDirect(byteSize));
2327
}
2428
} else {
2529
try (val socket = new Socket(ipAddress, port)) {
26-
if (sendResult && socket.isConnected()) {
30+
if (sendResult && socket.isConnected())
2731
Main.runner.getLogger().print(Logger.LEVEL.INFO, String.format("Connected! ip: %s, port: %s, threads: %s\n", ipAddress, port, Main.runner.getTaskManager().tasks.size()));
32+
33+
if(writeBytes){
34+
val os = new DataOutputStream(socket.getOutputStream());
35+
os.write((byte) byteSize);
36+
os.close();
2837
}
29-
if (keepAlive) {
38+
if (keepAlive)
3039
socket.setKeepAlive(true);
31-
} else
40+
else
3241
socket.close();
3342
}
3443
}

src/main/java/ir/xenoncommunity/utils/TaskManager.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ public void add(final Thread threadIn){
1010
}
1111
public void remove(final int idIn){
1212
tasks.get(idIn).interrupt();
13+
tasks.remove(idIn);
1314
}
1415
public void doTasks(){
1516
tasks.forEach(Thread::start);

0 commit comments

Comments
 (0)