private void PostSend(byte[] buf) { if (ConnectionState.Connected == state) { SendStateObject sendObj = new SendStateObject(); sendObj.buffer = new Gamnet.Buffer(buf); _socket.BeginSend(sendObj.buffer.data, 0, sendObj.buffer.Size(), 0, new AsyncCallback(Callback_OnSend), sendObj); } else { sendQueue.Enqueue(buf); } }
private void PostSend(byte[] buf) { if (State.Connected == state) { SendStateObject sendObj = new SendStateObject(); sendObj.socket = _socket; sendObj.buffer = new Gamnet.Buffer(); sendObj.buffer.Copy(buf); _socket.BeginSend(buf, 0, buf.Length, 0, new AsyncCallback(Callback_OnSend), sendObj); } else { sendQueue.Enqueue(buf); } }
public bool Send(object msg) { try { UInt16 id; ArraySegment <byte> sendArraySegment = Encode(msg, out id); SendStateObject sendState = new SendStateObject(); sendState.StateSocket = this.socket; sendState.Size = sendArraySegment.Count; sendState.Id = id; int t = this.nClient.SendTo(sendArraySegment); return(true); } catch (Exception e) { Debug.Log("transporter send exception :" + e.ToString()); return(false); } }
private void Callback_OnSend(IAsyncResult result) { try { SendStateObject obj = (SendStateObject)result.AsyncState; int writedBytes = _socket.EndSend(result); obj.buffer.readIndex += writedBytes; if (obj.buffer.Size() > 0) { Gamnet.Buffer newBuffer = new Gamnet.Buffer(obj.buffer); AsyncSend(newBuffer.buffer); } } catch (System.Exception error) { Error(error); Close(); } }
private void BeginSendCallback(IAsyncResult iar) { SendStateObject state = (SendStateObject)iar.AsyncState !; try { if (state.Socket.EndSend(iar) <= 0) { InvokeClientDisconnect(state.Socket, DisconnectReason.Unspecified); } } catch { /* IGNORE */ } finally { ByteArrayPool.Return(state.Buffer); } }
/// <summary> /// 回调函数 /// </summary> /// <param name="rs"></param> public void SendCallBack(IAsyncResult rs) { if (rs.IsCompleted) { SendStateObject state = rs.AsyncState as SendStateObject; WebRequest rq = state.rq; try { WebResponse response = rq.GetResponse(); Stream dataStream = state.str; dataStream = response.GetResponseStream(); sys_FrameWorkInfoTable Webfi = new BinaryFormatter().Deserialize(dataStream) as sys_FrameWorkInfoTable; //CheckOk = true; CheckReturn = Webfi; if (Convert.ToDecimal(FrameSystemInfo.GetSystemInfoTable.S_FrameWorkInfo.S_Version.Replace(".","")) < Convert.ToDecimal(Convert.ToDecimal(Webfi.S_Version.Replace(".","")))) { CheckNewVer = true; } //更新Licensed验证字段 if (Webfi.S_Licensed == "False") _CheckLicensed = false; } //catch (Exception ex) //{ // if (ex.InnerException != null) ex = ex.InnerException; // if (Common.DispError == false) // FileTxtLogs.WriteLog(ex.Source + " thrown " + ex.GetType().ToString() + "<br />" + ex.Message.Replace("\r", "").Replace("\n", "<br />") + "<br />" + ex.StackTrace.Replace("\r", "").Replace("\n", "<br />")); //} finally { rq.Abort(); //response.Close(); //dataStream.Close(); } } }
/// <summary> /// Sends the given byte array. /// </summary> /// <param name="byteData"></param> public void send(byte[] byteData) { // Den asynchronen Sendevorgang anstoßen. try { SendStateObject state = new SendStateObject(); state.socket = _socket; state.data = byteData; if (_socket == null) throw new Exception("Can not send when Socket is not open"); _socket.BeginSend(byteData, 0, byteData.Length, SocketFlags.None, new AsyncCallback(sendCallback), state); } catch (SocketException e) { handleException(e); } }
public SockMgrSendEventArgs(SockMgr handler, SendStateObject state, object externalCallbackState = null) { State = state; ExternalCallbackState = externalCallbackState; base.Handler = handler; }