Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
amos-boot-biz
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
项目统一框架
amos-boot-biz
Commits
609e8cb8
Commit
609e8cb8
authored
Oct 10, 2023
by
xinglei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
*)修改线程
parent
5b1ccbe3
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
4 deletions
+30
-4
ClientHandler.java
.../main/java/com/yeejoin/amos/kgd/config/ClientHandler.java
+20
-0
SocketConfig.java
...c/main/java/com/yeejoin/amos/kgd/config/SocketConfig.java
+10
-4
No files found.
amos-boot-module/amos-boot-module-api/amos-boot-module-kgd-api/src/main/java/com/yeejoin/amos/kgd/config/ClientHandler.java
View file @
609e8cb8
...
...
@@ -37,4 +37,23 @@ public class ClientHandler implements Runnable {
e
.
printStackTrace
();
}
}
public
static
void
main
(
String
[]
args
)
throws
Exception
{
requestInfoToSocketServer
();
}
private
static
void
requestInfoToSocketServer
()
{
try
{
Socket
socket
=
new
Socket
(
"127.0.0.1"
,
7777
);
PrintWriter
out
=
new
PrintWriter
(
socket
.
getOutputStream
(),
true
);
out
.
write
(
"我是客户端"
);
out
.
flush
();
socket
.
shutdownOutput
();
//开始接收服务端的消息
BufferedReader
in
=
new
BufferedReader
(
new
InputStreamReader
(
socket
.
getInputStream
()));
log
.
info
(
"接收到服务端的回复:"
+
in
.
readLine
());
}
catch
(
Exception
e
)
{
log
.
info
(
"Socket传输数据异常!"
+
e
.
getMessage
());
}
}
}
\ No newline at end of file
amos-boot-module/amos-boot-module-api/amos-boot-module-kgd-api/src/main/java/com/yeejoin/amos/kgd/config/SocketConfig.java
View file @
609e8cb8
...
...
@@ -9,6 +9,9 @@ import javax.annotation.PostConstruct;
import
java.io.IOException
;
import
java.net.ServerSocket
;
import
java.net.Socket
;
import
java.util.concurrent.LinkedBlockingQueue
;
import
java.util.concurrent.ThreadPoolExecutor
;
import
java.util.concurrent.TimeUnit
;
/**
* @Author: xl
...
...
@@ -23,6 +26,9 @@ public class SocketConfig {
@Value
(
"${socket.port}"
)
private
Integer
port
;
private
static
final
ThreadPoolExecutor
threadpool
=
new
ThreadPoolExecutor
(
15
,
15
,
10L
,
TimeUnit
.
SECONDS
,
new
LinkedBlockingQueue
<
Runnable
>());
@PostConstruct
public
void
socketStart
()
{
//直接另起一个线程挂起Socket服务
...
...
@@ -33,12 +39,12 @@ public class SocketConfig {
ServerSocket
ss
=
null
;
try
{
ss
=
new
ServerSocket
(
port
);
log
.
info
(
"socket端口在:
{}
中开启并持续监听=====>"
,
port
);
while
(
true
)
{
log
.
info
(
"socket端口在:
【{}】
中开启并持续监听=====>"
,
port
);
while
(
Boolean
.
TRUE
)
{
Socket
socket
=
ss
.
accept
();
// 创建新线程处理连接
Thread
thread
=
new
Thread
(
new
ClientHandler
(
socket
));
thread
.
start
(
);
log
.
info
(
"接收到客户端socket: {}"
,
socket
.
getRemoteSocketAddress
(
));
thread
pool
.
execute
(
new
ClientHandler
(
socket
)
);
}
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
e
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment