public virtual void OnReceived(byte[] data) { try { mFileGettedSize += data.Length; if (mUploadFileHandler != null) { mUploadFileHandler.OnGettingFileData(data); } SendData(MessageType.Result, mFileGettedSize, ""); if (mFileGettedSize >= mCurrentBag.FileSize) { if (mUploadFileHandler != null) { mUploadFileHandler.OnUploadFileCompleted(); } mUploadFileHandler = null; //重新接收text this.StreamType = RemotingStreamType.Text; SendData(MessageType.Result, "ok", ""); } } catch (Exception ex) { this.StreamType = RemotingStreamType.Text; var baseException = ex.GetBaseException(); SendData(MessageType.InvokeError, baseException != null ? baseException.Message : ex.Message, ""); } }
public RemotingClientHandler(SendDataHandler sendFunc, Action closeStreamHandler, string clientIP, string referer, GetHeaderValueHandler getHeaderValueHandler) { _Referer = referer; mCloseStreamHandler = closeStreamHandler; mSendDataFunc = sendFunc; this.StreamType = RemotingStreamType.Text; mClientIP = clientIP; _heartTime = DateTime.Now; _GetHeaderValueHandler = getHeaderValueHandler; }
public virtual void OnReceived(string data) { try { MessageBag msgBag = Newtonsoft.Json.JsonConvert.DeserializeObject <MessageBag>(data); mCurrentBag = msgBag; if (this.Session == null) { if (msgBag.SessionID.IsNullOrEmpty()) { this.Session = SessionState.GetSession(Guid.NewGuid().ToString()); } else { this.Session = SessionState.GetSession(msgBag.SessionID); if (this.Session == null) { this.Session = SessionState.GetSession(Guid.NewGuid().ToString()); } } } if (msgBag.Action == "init") { handleInit(msgBag); } else if (msgBag.Action == "exit") { mCloseStreamHandler(); } else if (msgBag.Action == "UploadFile") { this.StreamType = RemotingStreamType.Bytes; handleUploadFile(msgBag); } else if (msgBag.Action == "w_heart")//websocket心跳包 { SendClientMessage("1", 2); return; } else if (msgBag.Action == "w_msg")//websocket消息 { RemotingController.MessageReceive(this.Session, msgBag.State); return; } else if (msgBag.MethodName.IsNullOrEmpty() == false) { handleMethodInvoke(msgBag); } else if (msgBag.GroupName.IsNullOrEmpty() == false) { this.GroupName = msgBag.GroupName; if (RemotingController.MessageReceiverConnect(this.Session, this.GroupName) == false) { throw new Exception("服务器拒绝你接收信息"); } KeepAliveHandlers.Add(this); return; } } catch (Exception ex) { throw ex; } }