[+] 完善socket信令

This commit is contained in:
acgist
2023-02-14 08:14:23 +08:00
parent 78fa48c35c
commit 778b933000
59 changed files with 751 additions and 679 deletions

View File

@@ -0,0 +1,22 @@
package com.acgist.taoyao.listener;
import org.springframework.boot.context.event.ApplicationStartingEvent;
import org.springframework.context.ApplicationListener;
/**
* 配置JDK HTTPClient域名校验问题
*
* 注意SpringApplicationRunListeners里面同步执行
*
* @author acgist
*/
public class HTTPClientListener implements ApplicationListener<ApplicationStartingEvent> {
@Override
public void onApplicationEvent(ApplicationStartingEvent event) {
synchronized (HTTPClientListener.class) {
System.getProperties().setProperty("jdk.internal.httpclient.disableHostnameVerification", Boolean.TRUE.toString());
}
}
}

View File

@@ -9,7 +9,6 @@ import org.springframework.context.annotation.ComponentScan;
public class TaoyaoApplication {
public static void main(String[] args) {
System.getProperties().setProperty("jdk.internal.httpclient.disableHostnameVerification", Boolean.TRUE.toString());
SpringApplication.run(TaoyaoApplication.class, args);
}

View File

@@ -0,0 +1 @@
org.springframework.context.ApplicationListener=com.acgist.taoyao.listener.HTTPClientListener

View File

@@ -0,0 +1,8 @@
taoyao:
script:
media-reboot: pm2 restart taoyao-media-server
media-shutdown: pm2 stop taoyao-media-server
system-reboot: shutdown -s -t 0
system-shutdown: shutdown -r -t 0
platform-reboot: net stop taoyao-signal-server & net start taoyao-signal-server
platform-shutdown: net stop taoyao-signal-server

View File

@@ -52,7 +52,6 @@ taoyao:
version: 1.0.0
description: 桃夭WebRTC信令服务
timeout: 5000
max-timeout: 120000
id:
sn: 0
max-index: 999999
@@ -116,11 +115,13 @@ taoyao:
enabled: true
host: 0.0.0.0
port: 9999
timeout: ${taoyao.timeout}
queue-size: 100000
thread-min: 4
thread-max: 128
thread-name-prefix: ${spring.application.name}-signal-
keep-alive-time: 60
buffer-size: 2048
# WebRTC配置
webrtc:
# STUN服务
@@ -147,19 +148,10 @@ taoyao:
client: 0 * * * * ?
# 脚本配置
script:
# Linux
linux:
media-reboot: pm2 restart taoyao-media-server
media-shutdown: pm2 stop taoyao-media-server
system-reboot: reboot
system-shutdown: shutdown now
platform-reboot: systemctl restart taoyao-signal-server
platform-shutdown: systemctl stop taoyao-signal-server
# Windows
windows:
media-reboot: pm2 restart taoyao-media-server
media-shutdown: pm2 stop taoyao-media-server
system-reboot: shutdown -s -t 0
system-shutdown: shutdown -r -t 0
platform-reboot: net stop taoyao-signal-server & net start taoyao-signal-server
platform-shutdown: net stop taoyao-signal-server
enabled: true
media-reboot: pm2 restart taoyao-media-server
media-shutdown: pm2 stop taoyao-media-server
system-reboot: reboot
system-shutdown: shutdown now
platform-reboot: systemctl restart taoyao-signal-server
platform-shutdown: systemctl stop taoyao-signal-server

View File

@@ -1,21 +1,58 @@
package com.acgist.taoyao.signal;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import org.junit.jupiter.api.Test;
public class SocketSignalTest {
import com.acgist.taoyao.signal.protocol.Constant;
import lombok.extern.slf4j.Slf4j;
@Slf4j
public class SocketSignalTest {
@Test
void test() throws UnknownHostException, IOException {
void testSocket() throws Exception {
final Socket socket = new Socket();
socket.connect(new InetSocketAddress("127.0.0.1", 9999));
final OutputStream outputStream = socket.getOutputStream();
outputStream.write("{}".getBytes());
final InputStream inputStream = socket.getInputStream();
final String line = Constant.LINE;
final int lineLength = line.length();
new Thread(() -> {
int index = 0;
int length = 0;
final byte[] bytes = new byte[1024];
final StringBuilder builder = new StringBuilder();
try {
while((length = inputStream.read(bytes)) >= 0) {
builder.append(new String(bytes, 0, length));
while((index = builder.indexOf(line)) >= 0) {
log.info("收到消息:{}", builder.substring(0, index));
builder.delete(0, index + lineLength);
}
}
} catch (IOException e) {
log.error("读取异常", e);
}
}).start();
final Executor executor = Executors.newFixedThreadPool(10);
for (int index = 0; index < 100; index++) {
executor.execute(() -> {
try {
outputStream.write(("{}" + line).getBytes());
} catch (IOException e) {
log.error("发送异常", e);
}
});
}
Thread.sleep(5000);
socket.close();
}