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
1804918c
Commit
1804918c
authored
Oct 11, 2023
by
xinglei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
*)修改socket方法
parent
0820bba2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
33 additions
and
9 deletions
+33
-9
ClientHandler.java
.../main/java/com/yeejoin/amos/kgd/config/ClientHandler.java
+27
-5
SocketConfig.java
...c/main/java/com/yeejoin/amos/kgd/config/SocketConfig.java
+6
-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 @
1804918c
package
com
.
yeejoin
.
amos
.
kgd
.
config
;
package
com
.
yeejoin
.
amos
.
kgd
.
config
;
import
com.alibaba.fastjson.JSON
;
import
com.yeejoin.amos.component.feign.model.FeignClientResult
;
import
com.yeejoin.amos.component.robot.AmosRequestContext
;
import
com.yeejoin.amos.feign.privilege.Privilege
;
import
com.yeejoin.amos.feign.privilege.model.AgencyUserModel
;
import
org.slf4j.Logger
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.slf4j.LoggerFactory
;
import
org.typroject.tyboot.core.foundation.context.RequestContext
;
import
org.typroject.tyboot.core.foundation.context.SpringContextHelper
;
import
java.io.*
;
import
java.io.*
;
import
java.net.Socket
;
import
java.net.Socket
;
import
java.util.Objects
;
/**
/**
* @Author: xl
* @Author: xl
...
@@ -24,13 +32,12 @@ public class ClientHandler implements Runnable {
...
@@ -24,13 +32,12 @@ public class ClientHandler implements Runnable {
@Override
@Override
public
void
run
()
{
public
void
run
()
{
try
{
try
{
log
.
info
(
"Received message from client: "
);
// 获取输入流和输出流
// 获取输入流和输出流
InputStream
inputStream
=
socket
.
getInputStream
();
InputStream
inputStream
=
socket
.
getInputStream
();
// 处理客户端请求
,逻辑写到这⬇⬇⬇⬇⬇⬇⬇
// 处理客户端请求
log
.
info
(
"收到客户端数据: "
);
String
path
=
this
.
upload2Maas
(
inputStream
);
log
.
info
(
"
Received message from client: "
);
log
.
info
(
"
调用maas服务返回结果: {}"
,
path
);
// 关闭连接
// 关闭连接
socket
.
close
();
socket
.
close
();
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
...
@@ -38,6 +45,21 @@ public class ClientHandler implements Runnable {
...
@@ -38,6 +45,21 @@ public class ClientHandler implements Runnable {
}
}
}
}
// 上传maas逻辑写到这⬇⬇⬇⬇⬇⬇⬇,然后把maas返回的资源路径返回,后续作为客户端的回传信息
private
String
upload2Maas
(
InputStream
inputStream
)
{
AmosRequestContext
robotAuthentication
=
SpringContextHelper
.
getBean
(
AmosRequestContext
.
class
);
if
(
Objects
.
nonNull
(
robotAuthentication
))
{
RequestContext
.
setAppKey
(
robotAuthentication
.
getAppKey
());
RequestContext
.
setProduct
(
robotAuthentication
.
getProduct
());
RequestContext
.
setToken
(
robotAuthentication
.
getToken
());
}
// 测试案例,上传maas需要token,用机器人账户登录上传,此处修改为真实请求⬇⬇⬇⬇⬇⬇⬇
FeignClientResult
<
AgencyUserModel
>
getme
=
Privilege
.
agencyUserClient
.
getme
();
System
.
out
.
println
(
JSON
.
toJSONString
(
getme
));
return
null
;
}
public
static
void
main
(
String
[]
args
)
throws
Exception
{
public
static
void
main
(
String
[]
args
)
throws
Exception
{
requestInfoToSocketServer
();
requestInfoToSocketServer
();
}
}
...
...
amos-boot-module/amos-boot-module-api/amos-boot-module-kgd-api/src/main/java/com/yeejoin/amos/kgd/config/SocketConfig.java
View file @
1804918c
...
@@ -23,7 +23,7 @@ public class SocketConfig {
...
@@ -23,7 +23,7 @@ public class SocketConfig {
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
SocketConfig
.
class
);
private
static
final
Logger
log
=
LoggerFactory
.
getLogger
(
SocketConfig
.
class
);
@Value
(
"${socket.port}"
)
@Value
(
"${
amos.system.
socket.port}"
)
private
Integer
port
;
private
Integer
port
;
private
static
final
ThreadPoolExecutor
threadpool
=
new
ThreadPoolExecutor
(
15
,
15
,
private
static
final
ThreadPoolExecutor
threadpool
=
new
ThreadPoolExecutor
(
15
,
15
,
...
@@ -41,10 +41,12 @@ public class SocketConfig {
...
@@ -41,10 +41,12 @@ public class SocketConfig {
ss
=
new
ServerSocket
(
port
);
ss
=
new
ServerSocket
(
port
);
log
.
info
(
"socket端口在: 【{}】中开启并持续监听=====>"
,
port
);
log
.
info
(
"socket端口在: 【{}】中开启并持续监听=====>"
,
port
);
while
(
Boolean
.
TRUE
)
{
while
(
Boolean
.
TRUE
)
{
Socket
socket
=
ss
.
accept
();
Socket
clientSocket
=
ss
.
accept
();
//设置流读取的超时时间,这里设置为10s。超时后自动断开连接
clientSocket
.
setSoTimeout
(
10000
);
// 创建新线程处理连接
// 创建新线程处理连接
log
.
info
(
"接收到客户端socket: {}"
,
s
ocket
.
getRemoteSocketAddress
());
log
.
info
(
"接收到客户端socket: {}"
,
clientS
ocket
.
getRemoteSocketAddress
());
threadpool
.
execute
(
new
ClientHandler
(
s
ocket
));
threadpool
.
execute
(
new
ClientHandler
(
clientS
ocket
));
}
}
}
catch
(
IOException
e
)
{
}
catch
(
IOException
e
)
{
throw
new
RuntimeException
(
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