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
996d6238
Commit
996d6238
authored
Oct 10, 2023
by
xinglei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
*)修改socket逻辑
parent
b1dbc050
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
1 deletion
+56
-1
ClientHandler.java
.../main/java/com/yeejoin/amos/kgd/config/ClientHandler.java
+41
-0
SocketConfig.java
...c/main/java/com/yeejoin/amos/kgd/config/SocketConfig.java
+15
-1
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
0 → 100644
View file @
996d6238
package
com
.
yeejoin
.
amos
.
kgd
.
config
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
java.io.*
;
import
java.net.Socket
;
/**
* @Author: xl
* @Description:
* @Date: 2023/10/10 16:21
*/
public
class
ClientHandler
implements
Runnable
{
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
ClientHandler
.
class
);
private
Socket
socket
;
public
ClientHandler
(
Socket
socket
)
{
this
.
socket
=
socket
;
}
@Override
public
void
run
()
{
try
{
log
.
info
(
"Received message from client: "
);
// 获取输入流和输出流
InputStream
inputStream
=
socket
.
getInputStream
();
// 处理客户端请求,逻辑写到这⬇⬇⬇⬇⬇⬇⬇
log
.
info
(
"Received message from client: "
);
// 关闭连接
socket
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
\ 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 @
996d6238
...
@@ -3,6 +3,9 @@ package com.yeejoin.amos.kgd.config;
...
@@ -3,6 +3,9 @@ package com.yeejoin.amos.kgd.config;
import
org.springframework.context.annotation.Configuration
;
import
org.springframework.context.annotation.Configuration
;
import
javax.annotation.PostConstruct
;
import
javax.annotation.PostConstruct
;
import
java.io.IOException
;
import
java.net.ServerSocket
;
import
java.net.Socket
;
/**
/**
* @Author: xl
* @Author: xl
...
@@ -14,6 +17,17 @@ public class SocketConfig {
...
@@ -14,6 +17,17 @@ public class SocketConfig {
@PostConstruct
@PostConstruct
public
void
init
()
{
public
void
init
()
{
ServerSocket
ss
=
null
;
try
{
ss
=
new
ServerSocket
(
7777
);
while
(
true
)
{
Socket
socket
=
ss
.
accept
();
// 创建新线程处理连接
Thread
thread
=
new
Thread
(
new
ClientHandler
(
socket
));
thread
.
start
();
}
}
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