コード例 #1
0
        private void MyServer_NewRequestReceived(HansAppSession session, HansRequestInfo requestInfo)
        {
            string msg = requestInfo.Body.StartMark + requestInfo.Body.BodyString + requestInfo.Body.EndMark;//encoding.GetString(requestInfo.Body.BodyBuffer);

            if (msg.Contains("101,"))
            {
                //心跳
                TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
                session.Send("{\"code\":1001,\"result\":0,\"timestamp\": " + Convert.ToInt64(ts.TotalSeconds) + "}");
            }
            else if (msg.Contains("104,"))
            {
                //状态
                dynamic result = JsonConvert.DeserializeObject <dynamic>(msg);//反序列化
                //缓存设备状态
                using (RedisHashService service = new RedisHashService())
                {
                    service.SetEntryInHash("104", result.id.Value, result.st.on.Value.ToString());
                }
            }
                        log.Debug(msg);
        }
コード例 #2
0
 void myServer_SessionClosed(HansAppSession session, SuperSocket.SocketBase.CloseReason value)
 {
     throw new NotImplementedException();
 }
コード例 #3
0
 private void MyServer_NewSessionConnected(HansAppSession session)
 {
     //session.Send("Welcome to SuperSocket Telnet Server");
 }