苏州平台访问地址增加
This commit is contained in:
parent
a60eb4f951
commit
cc9cd8b00f
|
|
@ -31,3 +31,5 @@
|
||||||
/Waste.CreateDB/obj
|
/Waste.CreateDB/obj
|
||||||
/Waste.SocketService.cs/bin
|
/Waste.SocketService.cs/bin
|
||||||
/Waste.SocketService.cs/obj
|
/Waste.SocketService.cs/obj
|
||||||
|
/WasteHexTest/obj
|
||||||
|
/WasteHexTest/bin
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
https://iot.ljflytjl.cn/Developer/Devices
|
||||||
|
|
@ -8,14 +8,14 @@ using System.Threading.Tasks;
|
||||||
|
|
||||||
namespace WasteConsoleTest
|
namespace WasteConsoleTest
|
||||||
{
|
{
|
||||||
public class WSocketClientHelp
|
public class WSocketClientHelp
|
||||||
{
|
{
|
||||||
ClientWebSocket ws = null;
|
private ClientWebSocket ws = null;
|
||||||
Uri uri = null;
|
private Uri uri = null;
|
||||||
bool isUserClose = false;//是否最后由用户手动关闭
|
private bool isUserClose = false;//是否最后由用户手动关闭
|
||||||
public static string Secret = "T2hZmT3LhIvl0a0E";
|
public static string Secret = "ai5ak2Q5TpkOLO4T";
|
||||||
public static string SecretHash = "bvfEFN9CegW1SLEOlOGA5d+ht3RlXrmAOAr099AG7K8=";
|
public static string SecretHash = "6c29321e21e9c202";
|
||||||
public static string deviceid = "08d97f54-c0f6-4f57-81aa-296f93be7eb2";
|
public static string deviceid = "08d99b6b-a16f-4a5a-81ad-ffeaa9fdc94e";
|
||||||
|
|
||||||
// <summary>
|
// <summary>
|
||||||
/// WebSocket状态
|
/// WebSocket状态
|
||||||
|
|
@ -26,20 +26,24 @@ namespace WasteConsoleTest
|
||||||
/// 包含一个数据的事件
|
/// 包含一个数据的事件
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public delegate void MessageEventHandler(object sender, string data);
|
public delegate void MessageEventHandler(object sender, string data);
|
||||||
|
|
||||||
public delegate void ErrorEventHandler(object sender, Exception ex);
|
public delegate void ErrorEventHandler(object sender, Exception ex);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 连接建立时触发
|
/// 连接建立时触发
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public event EventHandler OnOpen;
|
public event EventHandler OnOpen;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 客户端接收服务端数据时触发
|
/// 客户端接收服务端数据时触发
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public event MessageEventHandler OnMessage;
|
public event MessageEventHandler OnMessage;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 通信发生错误时触发
|
/// 通信发生错误时触发
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public event ErrorEventHandler OnError;
|
public event ErrorEventHandler OnError;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 连接关闭时触发
|
/// 连接关闭时触发
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -67,7 +71,7 @@ namespace WasteConsoleTest
|
||||||
//初始化链接
|
//初始化链接
|
||||||
isUserClose = false;
|
isUserClose = false;
|
||||||
ws = new ClientWebSocket();
|
ws = new ClientWebSocket();
|
||||||
// ws.Options.AddSubProtocol("protocol1"); //使用的协议
|
// ws.Options.AddSubProtocol("protocol1"); //使用的协议
|
||||||
ws.Options.SetRequestHeader("device", deviceid); //设备ID
|
ws.Options.SetRequestHeader("device", deviceid); //设备ID
|
||||||
ws.Options.SetRequestHeader("secret", SecretHash); //设备secrethash
|
ws.Options.SetRequestHeader("secret", SecretHash); //设备secrethash
|
||||||
ws.Options.SetRequestHeader("time", GetTimestamp().ToString()); //时间戳
|
ws.Options.SetRequestHeader("time", GetTimestamp().ToString()); //时间戳
|
||||||
|
|
@ -134,8 +138,8 @@ namespace WasteConsoleTest
|
||||||
Close(ws.CloseStatus.Value, ws.CloseStatusDescription + netErr);
|
Close(ws.CloseStatus.Value, ws.CloseStatusDescription + netErr);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 增加记录分隔符
|
/// 增加记录分隔符
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -146,6 +150,7 @@ namespace WasteConsoleTest
|
||||||
List<byte> t = new List<byte>(data) { 0x1e };//0x1e record separator
|
List<byte> t = new List<byte>(data) { 0x1e };//0x1e record separator
|
||||||
return t.ToArray();
|
return t.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
//删除记录分隔符
|
//删除记录分隔符
|
||||||
private static byte[] RemoveSeparator(byte[] data)
|
private static byte[] RemoveSeparator(byte[] data)
|
||||||
{
|
{
|
||||||
|
|
@ -153,6 +158,7 @@ namespace WasteConsoleTest
|
||||||
t.Remove(0x1e);
|
t.Remove(0x1e);
|
||||||
return t.ToArray();
|
return t.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 获取时间戳
|
/// 获取时间戳
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -163,6 +169,7 @@ namespace WasteConsoleTest
|
||||||
int timestamp = Convert.ToInt32((DateTime.Now - dateTimeStart).TotalSeconds);
|
int timestamp = Convert.ToInt32((DateTime.Now - dateTimeStart).TotalSeconds);
|
||||||
return timestamp;
|
return timestamp;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 使用连接发送文本消息
|
/// 使用连接发送文本消息
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
@ -225,7 +232,6 @@ namespace WasteConsoleTest
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ws.Abort();
|
ws.Abort();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue