Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
sunxiaotianmg
Mozi.HttpEmbedded
提交
1480f0be
M
Mozi.HttpEmbedded
项目概览
sunxiaotianmg
/
Mozi.HttpEmbedded
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
M
Mozi.HttpEmbedded
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
1480f0be
编写于
7月 10, 2021
作者:
JasonWcx
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
修改部分事件实现
上级
e6bdda5f
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
40 addition
and
27 deletion
+40
-27
Mozi.SSDP.Test/Program.cs
Mozi.SSDP.Test/Program.cs
+2
-2
Mozi.SSDP/SSDPService.cs
Mozi.SSDP/SSDPService.cs
+7
-0
Mozi.StateService.Test/Program.cs
Mozi.StateService.Test/Program.cs
+4
-3
Mozi.StateService/HeartBeatGateway.cs
Mozi.StateService/HeartBeatGateway.cs
+15
-12
Mozi.StateService/HeartBeatService.cs
Mozi.StateService/HeartBeatService.cs
+1
-3
Mozi.StateService/HeartBeatSubscriber.cs
Mozi.StateService/HeartBeatSubscriber.cs
+8
-4
Mozi.StateService/UDPSocket.cs
Mozi.StateService/UDPSocket.cs
+3
-3
未找到文件。
Mozi.SSDP.Test/Program.cs
浏览文件 @
1480f0be
using
System
;
using
System.Net.NetworkInformation
;
using
Mozi.SSDP
;
using
Mozi.HttpEmbedded
;
namespace
Mozi.SSDP.Test
...
...
@@ -17,7 +16,7 @@ namespace Mozi.SSDP.Test
{
foreach
(
var
ip
in
r
.
GetIPProperties
().
UnicastAddresses
)
{
if
(
ip
.
Address
.
AddressFamily
==
System
.
Net
.
Sockets
.
AddressFamily
.
InterNetwork
)
if
(
ip
.
Address
.
AddressFamily
==
System
.
Net
.
Sockets
.
AddressFamily
.
InterNetwork
&&!
ip
.
Address
.
ToString
().
StartsWith
(
"169."
)
)
{
SSDPService
ssdp
=
new
SSDPService
();
ssdp
.
PackDefaultSearch
.
ST
=
new
TargetDesc
()
...
...
@@ -29,6 +28,7 @@ namespace Mozi.SSDP.Test
};
ssdp
.
MulticastAddress
=
"239.255.255.250"
;
ssdp
.
BindingAddress
=
ip
.
Address
;
Console
.
WriteLine
(
"binding start:{0},{1}"
,
ip
.
Address
,
r
.
Name
);
ssdp
.
OnNotifyAliveReceived
+=
Ssdp_OnNotifyAliveReceived
;
ssdp
.
OnSearchReceived
+=
Ssdp_OnSearchReceived
;
ssdp
.
OnNotifyByebyeReceived
+=
Ssdp_OnNotifyByebyeReceived
;
...
...
Mozi.SSDP/SSDPService.cs
浏览文件 @
1480f0be
...
...
@@ -110,10 +110,16 @@ namespace Mozi.SSDP
/// </para>
/// </summary>
public
bool
AllowLoopbackMessage
{
get
;
set
;
}
//224.0.0.0~224.0.0.255为预留的组播地址(永久组地址),地址224.0.0.0保留不做分配,其它地址供路由协议使用;
//224.0.1.0~224.0.1.255是公用组播地址,可以用于Internet;
//224.0.2.0~238.255.255.255为用户可用的组播地址(临时组地址),全网范围内有效;
//239.0.0.0~239.255.255.255为本地管理组播地址,仅在特定的本地范围内有效。
/// <summary>
/// 组播地址
/// <para>
/// 标准地址为 <see cref="SSDPProtocol.MulticastAddress"/> | <see cref="SSDPProtocol.MulticastAddressIPv6"/>
/// 范围为239.0.0.0~239.255.255.255
/// </para>
/// </summary>
public
string
MulticastAddress
...
...
@@ -124,6 +130,7 @@ namespace Mozi.SSDP
}
set
{
//值校验
_multicastGroupAddress
=
value
;
ApplyMulticastAddressChange
(
MulticastAddress
,
MulticastPort
);
}
...
...
Mozi.StateService.Test/Program.cs
浏览文件 @
1480f0be
...
...
@@ -25,15 +25,16 @@ namespace Mozi.StateService.Test
//服务网关
hg
.
AddSubscriber
(
new
Subscriber
()
{
Host
=
"100.100.0.171"
,
Port
=
13452
});
hg
.
AddSubscriber
(
new
Subscriber
()
{
Host
=
"100.100.0.105"
,
Port
=
13452
});
hg
.
OnClientOnlineStateChange
+=
Hg_OnClientStateChange
;
hg
.
OnClientMessageReceive
+=
Hg_OnClientMessageReceive
;
hg
.
OnClientMessageReceive
d
+=
Hg_OnClientMessageReceived
;
hg
.
OnClientUserChange
+=
Hg_OnClientUserChange
;
hg
.
OnClientJoin
+=
Hg_OnClientJoin
;
hg
.
OnClientLifeStateChange
+=
Hg_OnClientLifeStateChange
;
hg
.
Start
(
13453
);
hbs
.
OnClientOnlineStateChange
+=
Hg_OnClientStateChange
;
hbs
.
OnClientMessageReceive
+=
Hg_OnClientMessageReceive
;
hbs
.
OnClientMessageReceive
d
+=
Hg_OnClientMessageReceived
;
hbs
.
OnClientUserChange
+=
Hg_OnClientUserChange
;
hbs
.
OnClientJoin
+=
Hg_OnClientJoin
;
hbs
.
OnClientLifeStateChange
+=
Hg_OnClientLifeStateChange
;
...
...
@@ -80,7 +81,7 @@ namespace Mozi.StateService.Test
/// <param name="client"></param>
/// <param name="host"></param>
/// <param name="port"></param>
private
static
void
Hg_OnClientMessageReceive
(
object
sender
,
ClientAliveInfo
client
,
string
host
,
int
port
)
private
static
void
Hg_OnClientMessageReceive
d
(
object
sender
,
ClientAliveInfo
client
,
string
host
,
int
port
)
{
Console
.
WriteLine
(
"{4:MMdd HH:mm:ss}|N:{0},ID:{1},S:{2},V:{3},{5},{6}"
,
client
.
DeviceName
,
client
.
DeviceId
,
client
.
State
,
client
.
AppVersion
,
client
.
BeatTime
,
host
,
client
.
UserName
);
...
...
Mozi.StateService/HeartBeatGateway.cs
浏览文件 @
1480f0be
...
...
@@ -14,7 +14,7 @@ namespace Mozi.StateService
public
delegate
void
ClientJoinQuit
(
object
sender
,
ClientAliveInfo
clientInfo
);
public
delegate
void
ClientMessageReceive
(
object
sender
,
ClientAliveInfo
clientInfo
,
string
host
,
int
port
);
public
delegate
void
ClientMessageReceive
d
(
object
sender
,
ClientAliveInfo
clientInfo
,
string
host
,
int
port
);
public
class
ClientStateChangeArgs
:
EventArgs
{
...
...
@@ -39,6 +39,7 @@ namespace Mozi.StateService
public
DateTime
BeatTime
{
get
;
set
;
}
public
DateTime
OnTime
{
get
;
set
;
}
public
DateTime
LeaveTime
{
get
;
set
;
}
public
string
Host
{
get
;
set
;
}
public
ClientAliveInfo
()
{
...
...
@@ -82,19 +83,19 @@ namespace Mozi.StateService
/// <summary>
/// 终端通知状态变更
/// </summary>
public
ClientLifeStateChange
OnClientLifeStateChange
;
public
event
ClientLifeStateChange
OnClientLifeStateChange
;
/// <summary>
/// 终端在线状态变更事件
/// </summary>
public
ClientOnlineStateChange
OnClientOnlineStateChange
;
public
event
ClientOnlineStateChange
OnClientOnlineStateChange
;
/// <summary>
/// 终端在线用户变更
/// </summary>
public
ClientUserChange
OnClientUserChange
;
public
event
ClientUserChange
OnClientUserChange
;
/// <summary>
/// 终端消息接收事件
/// </summary>
public
ClientMessageReceive
OnClientMessageReceive
;
public
event
ClientMessageReceived
OnClientMessageReceived
;
/// <summary>
/// 终端列表
/// </summary>
...
...
@@ -157,7 +158,7 @@ namespace Mozi.StateService
try
{
//触发终端状态变更事件
OnClientUserChange
.
BeginInvoke
(
this
,
client
,
clientOldUserName
,
client
.
UserName
,
null
,
null
);
OnClientUserChange
(
this
,
client
,
clientOldUserName
,
client
.
UserName
);
}
finally
{
...
...
@@ -182,7 +183,7 @@ namespace Mozi.StateService
try
{
//触发终端状态变更事件
OnClientLifeStateChange
.
BeginInvoke
(
this
,
client
,
clientOldState
,
client
.
State
,
null
,
null
);
OnClientLifeStateChange
(
this
,
client
,
clientOldState
,
client
.
State
);
}
finally
{
...
...
@@ -216,7 +217,7 @@ namespace Mozi.StateService
try
{
//触发终端在线状态变更事件
OnClientOnlineStateChange
.
BeginInvoke
(
this
,
client
,
clientOldState
,
client
.
ClientState
,
null
,
null
);
OnClientOnlineStateChange
(
this
,
client
,
clientOldState
,
client
.
ClientState
);
}
finally
{
...
...
@@ -256,6 +257,7 @@ namespace Mozi.StateService
var
client
=
_clients
.
Find
(
x
=>
x
.
DeviceName
.
Equals
(
ca
.
DeviceName
)
&&
x
.
DeviceId
.
Equals
(
ca
.
DeviceId
));
if
(
client
!=
null
)
{
client
.
Host
=
ca
.
Host
;
client
.
AppVersion
=
ca
.
AppVersion
;
client
.
UserName
=
ca
.
UserName
;
SetUserName
(
ref
client
,
ca
.
UserName
);
...
...
@@ -269,7 +271,7 @@ namespace Mozi.StateService
//终端加入事件
if
(
OnClientJoin
!=
null
)
{
OnClientJoin
.
BeginInvoke
(
this
,
ca
,
null
,
null
);
OnClientJoin
(
this
,
ca
);
}
}
client
.
BeatCount
++;
...
...
@@ -336,12 +338,13 @@ namespace Mozi.StateService
DeviceId
=
pg
.
DeviceId
,
AppVersion
=
pg
.
AppVersion
,
UserName
=
pg
.
UserName
,
State
=(
ClientLifeState
)
Enum
.
Parse
(
typeof
(
ClientLifeState
),
pg
.
StateName
.
ToString
())
State
=(
ClientLifeState
)
Enum
.
Parse
(
typeof
(
ClientLifeState
),
pg
.
StateName
.
ToString
()),
Host
=
args
.
IP
};
var
client
=
UpsertClient
(
ca
);
if
(
OnClientMessageReceive
!=
null
)
if
(
OnClientMessageReceive
d
!=
null
)
{
OnClientMessageReceive
.
BeginInvoke
(
this
,
client
,
args
.
IP
,
args
.
Port
,
null
,
null
);
OnClientMessageReceive
d
(
this
,
client
,
args
.
IP
,
args
.
Port
);
}
PostMessageToSubscribers
(
args
.
IP
,
args
.
Port
,
pg
);
}
...
...
Mozi.StateService/HeartBeatService.cs
浏览文件 @
1480f0be
using
System
;
using
System.Collections.Generic
;
using
System.Net
;
using
System.Net
;
using
System.Net.Sockets
;
using
System.Threading
;
...
...
Mozi.StateService/HeartBeatSubscriber.cs
浏览文件 @
1480f0be
using
System
;
using
System.Collections.Generic
;
namespace
Mozi.StateService
{
...
...
@@ -8,6 +7,10 @@ namespace Mozi.StateService
/// </summary>
public
class
HeartBeatSubscriber
:
HeartBeatGateway
{
/// <summary>
/// 终端消息接收事件
/// </summary>
public
new
event
ClientMessageReceived
OnClientMessageReceived
;
/// <summary>
/// 数据接收完成回调
/// </summary>
...
...
@@ -26,12 +29,13 @@ namespace Mozi.StateService
DeviceId
=
hbp
.
DeviceId
,
AppVersion
=
hbp
.
AppVersion
,
UserName
=
hbp
.
UserName
,
State
=
(
ClientLifeState
)
Enum
.
Parse
(
typeof
(
ClientLifeState
),
hbp
.
StateName
.
ToString
())
State
=
(
ClientLifeState
)
Enum
.
Parse
(
typeof
(
ClientLifeState
),
hbp
.
StateName
.
ToString
()),
Host
=
pg
.
SrcHost
};
var
client
=
UpsertClient
(
ca
);
if
(
OnClientMessageReceive
!=
null
)
if
(
OnClientMessageReceive
d
!=
null
)
{
OnClientMessageReceive
.
BeginInvoke
(
this
,
client
,
pg
.
SrcHost
,
pg
.
SrcPort
,
null
,
null
);
OnClientMessageReceive
d
(
this
,
client
,
pg
.
SrcHost
,
pg
.
SrcPort
);
}
}
catch
(
Exception
ex
)
...
...
Mozi.StateService/UDPSocket.cs
浏览文件 @
1480f0be
...
...
@@ -110,7 +110,7 @@ namespace Mozi.StateService
_sc
.
BeginReceiveFrom
(
so
.
Buffer
,
0
,
StateObject
.
BufferSize
,
SocketFlags
.
None
,
ref
so
.
RemoteEndPoint
,
CallbackReceive
,
so
);
if
(
OnReceiveStart
!=
null
)
{
OnReceiveStart
.
BeginInvoke
(
this
,
new
DataTransferArgs
(),
null
,
null
);
OnReceiveStart
(
this
,
new
DataTransferArgs
()
);
}
}
catch
(
Exception
ex
)
...
...
@@ -154,14 +154,14 @@ namespace Mozi.StateService
{
if
(
AfterReceiveEnd
!=
null
)
{
AfterReceiveEnd
.
BeginInvoke
(
this
,
AfterReceiveEnd
(
this
,
new
DataTransferArgs
()
{
Data
=
so
.
Data
.
ToArray
(),
IP
=
((
IPEndPoint
)
remote
).
Address
.
ToString
(),
Port
=
((
IPEndPoint
)
remote
).
Port
,
Socket
=
so
.
WorkSocket
}
,
null
,
null
);
});
}
UDPStateObject
stateobject
=
new
UDPStateObject
()
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录