之前開發基於WinForm監控的軟件
下圖是MSDN關於解釋
Hub:提供與連接到 Hub 的 SignalR 連接進行通信的方法
Global
using System;
using System
using System
using System
using System
using System
using System
using Microsoft
namespace LMSCitySignalR
{
public class Global : System
{
protected void Application_Start(object sender
{
RouteTable
}
protected void Session_Start(object sender
{
}
protected void Application_BeginRequest(object sender
{
}
protected void Application_AuthenticateRequest(object sender
{
}
protected void Application_Error(object sender
{
}
protected void Session_End(object sender
{
}
protected void Application_End(object sender
{
}
}
}
頁面代碼
<%@ Page Language=
<meta http
<!DOCTYPE html>
<html xmlns=
<head runat=
<meta http
<title>LH CityLMS Client</title>
</head>
<body>
<div id=
Client Mac Address:
<input id=
<input id=
<br>
User Name:<input id=
User Password:<input id=
<input id=
<br>
<input id=
<br />
<input id=
<br />
<input id=
<script src=
<script src=
<script src=
<script src=
<script type=
$(function () {
/*
* 參考鏈接:
*· Persistent Connection(HTTP持久鏈接)
*· Hub
*/
/*鏈接對應server端Hub對象*/
var cityLmsClient = nnection
citytServerResult = function (name
$(
+
};
/*斷開連接消息提示*/
cityLmsClient
alert(message);
};
/*操作消息提示*/
cityLmsClient
$(
};
nnection
/*鏈接wcf Server*/
$(
citynServer($(
});
/*應急操作*/
$(
cityLmsClient
});
/*用戶登錄*/
$(
cityLmsClient
});
/*啟動心跳包
$(
cityLmsClient
});
/*斷開連接*/
$(
cityLmsClient
});
});
/*日志顯示*/
nnection
});
</script>
</body>
</html>
cityLmsClientHub
using System;
using System
using System
using System
using System
using System
using System
using System
using DL_LMS_Server
using DL_LMS_Server
using DL_LMS_Server
using Microsoft
namespace LMSCitySignalR
{
public class cityLmsClientHub : Hub
{
ServiceCallBack serCallBack = null;
/// <summary>
/// 應急操作回調
/// </summary>
/// <param name=
/// <param name=
private void RealTimeCabChCallBackMessage_Event(object sender
{
COptRealTimeCabChResult optCabChresult = e
string _sMsg = string
DateTime
optCabChresult
optCabChresult
optCabChresult
optCabChresult
optCabChresult
optCabChresult
optCabChresult
optCabChresult
Clients
Clients
}
public void Hello()
{
Clients
}
private static bool bIsConnect = false;
private static string sMacAddress = null;
private static string sUserName = null;
private static string sUserPassword = null;
/// <summary>
///鏈接wcf Server
/// </summary>
/// <param name=
/// <returns></returns>
private CommunResult ConnService(string clientMacAddress)
{
CommunResult result = new CommunResult();
try
{
SvrRetMessage svrMessage = ClientComServiceFactory
if (!svrMessage
{
result
result
}
result
result
}
catch (EndpointNotFoundException e)
{
string mes = e
result
result
}
catch (TimeoutException e)
{
string mes = e
result
result
}
catch (Exception e)
{
string mes = e
result
result
}
return result;
}
/// <summary>
/// 斷開與wcf Server鏈接
/// </summary>
public void DisConnectSvr()
{
string _sDisConSvrMsg = string
Clients
Debug
}
/// <summary>
/// 客戶端與服務器端斷開連接
/// </summary>
/// <returns></returns>
private CommunResult DisConnService()
{
CommunResult result = new CommunResult();
try
{
ClientComServiceFactory
result
result
}
catch (EndpointNotFoundException e)
{
string mes = e
result
result
}
catch (TimeoutException e)
{
string mes = e
result
result
}
catch (Exception e)
{
string mes = e
result
result
}
return result;
}
/// <summary>
/// 心跳包
/// </summary>
public void MonitorClientChanel()
{
if (string
return;
ThreadPool
(
delegate
{
while (true)
{
Thread
try
{
Debug
if (ClientComServiceFactory
{
ClientComServiceFactory
ClientComServiceFactory
}
ClientComServiceFactory
}
catch (Exception ex)
{
ClientComServiceFactory
Debug
}
}
}
);
}
/// <summary>
/// 鏈接wcf Server
/// </summary>
/// <param name=
public void ConServer(string clientMacAddress)
{
//DebugerHelper dHelper = new DebugerHelper(DebugParameter
//dHelper
CommunResult _comStatus = ConnService(clientMacAddress);
//FormartDebuger(MethodBase
Clients
if (_comStatus
{
sMacAddress = clientMacAddress;
bIsConnect = true;
}
}
/// <summary>
/// 用戶登錄
/// </summary>
/// <param name=
/// <param name=
public void UserLogin(string sName
{
if (CheckConnectStatus())
{
LoginResult _serverLoginResult = ClientComServiceFactory
if (_serverLoginResult
{
sUserName = sName;
sUserPassword = sPassWord;
ServiceCallBack
}
Clients
}
}
/// <summary>
/// 應急操作
/// </summary>
public void EmergencyControl()
{
if (CheckConnectStatus())
{
OptRealCtuChannelParameter parameter = new OptRealCtuChannelParameter();
parameter
parameter
parameter
parameter
parameter
parameter
parameter
parameter
parameter
parameter
parameter
SvrRetMessage returnMessage = ClientComServiceFactory
Clients
}
}
/// <summary>
/// 檢查是否已經連接wcf Server
/// </summary>
/// <returns></returns>
private bool CheckConnectStatus()
{
if (bIsConnect && !string
return true;
else
Clients
return false;
}
}
}
實現效果
才疏學淺
From:http://tw.wingwit.com/Article/program/net/201311/12646.html