Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
guo450212436
et
提交
69e27c7a
E
et
项目概览
guo450212436
/
et
与 Fork 源项目一致
从无法访问的项目Fork
通知
3
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
E
et
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
69e27c7a
编写于
9月 10, 2018
作者:
T
tanghai
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
1.增加websocket错误提示
2.简化网络库代码
上级
596d8b22
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
59 addition
and
58 deletion
+59
-58
Server/Model/Module/Message/Network/WebSocket/WService.cs
Server/Model/Module/Message/Network/WebSocket/WService.cs
+42
-26
Unity/Assets/Scripts/Module/Message/Network/AService.cs
Unity/Assets/Scripts/Module/Message/Network/AService.cs
+0
-2
Unity/Assets/Scripts/Module/Message/Network/KCP/KService.cs
Unity/Assets/Scripts/Module/Message/Network/KCP/KService.cs
+7
-5
Unity/Assets/Scripts/Module/Message/Network/TCP/TService.cs
Unity/Assets/Scripts/Module/Message/Network/TCP/TService.cs
+7
-9
Unity/Assets/Scripts/Module/Message/NetworkComponent.cs
Unity/Assets/Scripts/Module/Message/NetworkComponent.cs
+3
-16
未找到文件。
Server/Model/Module/Message/Network/WebSocket/WService.cs
浏览文件 @
69e27c7a
...
...
@@ -14,20 +14,20 @@ namespace ETModel
public
RecyclableMemoryStreamManager
MemoryStreamManager
=
new
RecyclableMemoryStreamManager
();
public
WService
(
IEnumerable
<
string
>
prefixs
)
public
WService
(
IEnumerable
<
string
>
prefixs
,
Action
<
AChannel
>
acceptCallback
)
{
this
.
InstanceId
=
IdGenerater
.
GenerateId
();
this
.
AcceptCallback
+=
acceptCallback
;
this
.
httpListener
=
new
HttpListener
();
foreach
(
string
prefix
in
prefixs
)
{
this
.
httpListener
.
Prefixes
.
Add
(
prefix
);
}
StartAccept
(
prefixs
);
}
public
WService
()
{
this
.
InstanceId
=
IdGenerater
.
GenerateId
();
}
public
override
AChannel
GetChannel
(
long
id
)
...
...
@@ -68,33 +68,49 @@ namespace ETModel
}
public
override
async
void
Start
(
)
public
async
void
StartAccept
(
IEnumerable
<
string
>
prefixs
)
{
if
(
this
.
httpListener
==
null
)
try
{
return
;
}
httpListener
.
Start
();
while
(
true
)
{
try
foreach
(
string
prefix
in
prefixs
)
{
HttpListenerContext
httpListenerContext
=
await
this
.
httpListener
.
GetContextAsync
();
HttpListenerWebSocketContext
webSocketContext
=
await
httpListenerContext
.
AcceptWebSocketAsync
(
null
);
WChannel
channel
=
new
WChannel
(
webSocketContext
,
this
);
this
.
httpListener
.
Prefixes
.
Add
(
prefix
);
}
this
.
channels
[
channel
.
Id
]
=
channel
;
this
.
OnAccept
(
channel
);
httpListener
.
Start
();
while
(
true
)
{
try
{
HttpListenerContext
httpListenerContext
=
await
this
.
httpListener
.
GetContextAsync
();
HttpListenerWebSocketContext
webSocketContext
=
await
httpListenerContext
.
AcceptWebSocketAsync
(
null
);
WChannel
channel
=
new
WChannel
(
webSocketContext
,
this
);
this
.
channels
[
channel
.
Id
]
=
channel
;
this
.
OnAccept
(
channel
);
}
catch
(
Exception
e
)
{
Log
.
Error
(
e
);
}
}
catch
(
Exception
e
)
}
catch
(
HttpListenerException
e
)
{
if
(
e
.
ErrorCode
==
5
)
{
Log
.
Error
(
e
);
throw
new
Exception
(
$"CMD管理员中输入: netsh http add urlacl url=http://*:8080/ user=Everyone"
,
e
);
}
Log
.
Error
(
e
);
}
catch
(
Exception
e
)
{
Log
.
Error
(
e
);
}
}
}
...
...
Unity/Assets/Scripts/Module/Message/Network/AService.cs
浏览文件 @
69e27c7a
...
...
@@ -40,7 +40,5 @@ namespace ETModel
public
abstract
void
Remove
(
long
channelId
);
public
abstract
void
Update
();
public
abstract
void
Start
();
}
}
\ No newline at end of file
Unity/Assets/Scripts/Module/Message/Network/KCP/KService.cs
浏览文件 @
69e27c7a
...
...
@@ -57,8 +57,12 @@ namespace ETModel
private
EndPoint
ipEndPoint
=
new
IPEndPoint
(
IPAddress
.
Any
,
0
);
public
KService
(
IPEndPoint
ipEndPoint
)
public
KService
(
IPEndPoint
ipEndPoint
,
Action
<
AChannel
>
acceptCallback
)
{
this
.
InstanceId
=
ETModel
.
IdGenerater
.
GenerateId
();
this
.
AcceptCallback
+=
acceptCallback
;
this
.
StartTime
=
TimeHelper
.
ClientNow
();
this
.
TimeNow
=
(
uint
)(
TimeHelper
.
ClientNow
()
-
this
.
StartTime
);
this
.
socket
=
new
Socket
(
AddressFamily
.
InterNetwork
,
SocketType
.
Dgram
,
ProtocolType
.
Udp
);
...
...
@@ -78,6 +82,8 @@ namespace ETModel
public
KService
()
{
this
.
InstanceId
=
ETModel
.
IdGenerater
.
GenerateId
();
this
.
StartTime
=
TimeHelper
.
ClientNow
();
this
.
TimeNow
=
(
uint
)(
TimeHelper
.
ClientNow
()
-
this
.
StartTime
);
this
.
socket
=
new
Socket
(
AddressFamily
.
InterNetwork
,
SocketType
.
Dgram
,
ProtocolType
.
Udp
);
...
...
@@ -114,10 +120,6 @@ namespace ETModel
Instance
=
null
;
}
public
override
void
Start
()
{
}
public
void
Recv
()
{
if
(
this
.
socket
==
null
)
...
...
Unity/Assets/Scripts/Module/Message/Network/TCP/TService.cs
浏览文件 @
69e27c7a
...
...
@@ -20,18 +20,24 @@ namespace ETModel
/// <summary>
/// 即可做client也可做server
/// </summary>
public
TService
(
IPEndPoint
ipEndPoint
)
public
TService
(
IPEndPoint
ipEndPoint
,
Action
<
AChannel
>
acceptCallback
)
{
this
.
InstanceId
=
IdGenerater
.
GenerateId
();
this
.
AcceptCallback
+=
acceptCallback
;
this
.
acceptor
=
new
Socket
(
AddressFamily
.
InterNetwork
,
SocketType
.
Stream
,
ProtocolType
.
Tcp
);
this
.
acceptor
.
SetSocketOption
(
SocketOptionLevel
.
Socket
,
SocketOptionName
.
ReuseAddress
,
true
);
this
.
innArgs
.
Completed
+=
this
.
OnComplete
;
this
.
acceptor
.
Bind
(
ipEndPoint
);
this
.
acceptor
.
Listen
(
1000
);
this
.
AcceptAsync
();
}
public
TService
()
{
this
.
InstanceId
=
IdGenerater
.
GenerateId
();
}
public
override
void
Dispose
()
...
...
@@ -53,14 +59,6 @@ namespace ETModel
this
.
innArgs
.
Dispose
();
}
public
override
void
Start
()
{
if
(
this
.
acceptor
!=
null
)
{
this
.
AcceptAsync
();
}
}
private
void
OnComplete
(
object
sender
,
SocketAsyncEventArgs
e
)
{
switch
(
e
.
LastOperation
)
...
...
Unity/Assets/Scripts/Module/Message/NetworkComponent.cs
浏览文件 @
69e27c7a
...
...
@@ -35,10 +35,6 @@ namespace ETModel
break
;
#endif
}
this
.
Service
.
AcceptCallback
+=
this
.
OnAccept
;
this
.
Start
();
}
catch
(
Exception
e
)
{
...
...
@@ -55,23 +51,19 @@ namespace ETModel
{
case
NetworkProtocol
.
KCP
:
ipEndPoint
=
NetworkHelper
.
ToIPEndPoint
(
address
);
this
.
Service
=
new
KService
(
ipEndPoint
);
this
.
Service
=
new
KService
(
ipEndPoint
,
this
.
OnAccept
);
break
;
case
NetworkProtocol
.
TCP
:
ipEndPoint
=
NetworkHelper
.
ToIPEndPoint
(
address
);
this
.
Service
=
new
TService
(
ipEndPoint
);
this
.
Service
=
new
TService
(
ipEndPoint
,
this
.
OnAccept
);
break
;
#if SERVER
case
NetworkProtocol
.
WebSocket
:
string
[]
prefixs
=
address
.
Split
(
';'
);
this
.
Service
=
new
WService
(
prefixs
);
this
.
Service
=
new
WService
(
prefixs
,
this
.
OnAccept
);
break
;
#endif
}
this
.
Service
.
AcceptCallback
+=
this
.
OnAccept
;
this
.
Start
();
}
catch
(
Exception
e
)
{
...
...
@@ -79,11 +71,6 @@ namespace ETModel
}
}
public
void
Start
()
{
this
.
Service
.
Start
();
}
public
int
Count
{
get
{
return
this
.
sessions
.
Count
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录