void OnRecievedData() { while (state >= 0) { try { byte[] receiveBytes = m_UdpClient.Receive(ref mIPEndPoint); if (null != receiveBytes) { m_RecvQueue.Push(receiveBytes); } } catch (SocketException ee) { #if DEBUG if (ee.NativeErrorCode == 10054) { Console.WriteLine("无法连接到远程服务器"); } else { Console.WriteLine(ee.ToString()); } #endif this.Status = ClientSessionStatus.ConnectFail; var e = Event; if (e != null) { e(UdpClientEvents.ConnectFail, null); } return; } } }
public void pushData(byte[] data) { // push udp packet to switch queue. mRecvQueue.Push(data); //临时用用 //Update(); }
void ReceiveCallback(IAsyncResult ar) { try { Byte[] data = (mIPEndPoint == null) ? mUdpClient.Receive(ref mIPEndPoint) : mUdpClient.EndReceive(ar, ref mIPEndPoint); if (null != data) { // push udp packet to switch queue. mRecvQueue.Push(data); } if (mUdpClient != null) { // try to receive again. mUdpClient.BeginReceive(ReceiveCallback, this); } } catch (Exception e) { // itfantasy added if (this.errHandler != null) { this.errHandler.Invoke(e.Message); } } }
override protected void Processingdata(int _len, byte[] _buffer) { try { if (cacheBytesQue.PopCount <= 0) { cacheBytesQue.Switch(); } CacheByteObject dst = null; if (cacheBytesQue.PopCount > 0) { dst = cacheBytesQue.Dequeue(); dst.Initialize(); } else { dst = new CacheByteObject() { bytes = new byte[cacheByteLen] }; } dst.length = _len; Buffer.BlockCopy(_buffer, 0, dst.bytes, 0, _len); recvQueue.Push(dst); } catch (Exception e) { DLog.LogError(mNetTag + "-" + e.ToString()); } }
void RecThread() { while (taskStart) { try { if (testServer.Available != 0) { int receiveNumber = testServer.ReceiveFrom(recbuffer, SocketFlags.None, ref mRecPoint); IPEndPoint tremot = (IPEndPoint)mRecPoint; if (receiveNumber > 0) { tarpoint = tremot; byte[] dst = new byte[receiveNumber]; Buffer.BlockCopy(recbuffer, 0, dst, 0, receiveNumber); recvQueue.Push(dst); //ShowBuffer(recbuffer,receiveNumber); } } } catch (Exception e) { Debug.LogError("UDP接收线程异常:" + e); } Thread.Sleep(1); } }
private static void InputWorker() { while (!_disposed) { string cmd = Console.ReadLine(); INPUT_QUEUE.Push(cmd); Thread.Sleep(10); } }
public void KcpListen() { while (!exitFlag) { var data = new byte[1024]; var recv = server.ReceiveFrom(data, ref remote); var callbackBuff = new byte[recv]; Buffer.BlockCopy(data, 0, callbackBuff, 0, recv); receiveQueue.Push(callbackBuff); } }
void OnRecievedData() { while (state >= 0) { try { if (index == 0) { recvBuf = new byte[DEF_SIZE]; //接收缓冲区大小 index = 2; } else if (index == 1) { result = socket.ReceiveFrom(recvBuf, ref srvEnd); if (result > 0) { if (result > recvBuf.Length) { //Main.Debug("接受到的数据大于缓冲区了:"); } else { byte[] receiveBytes = new byte[result]; //UnityEngine.Main.Debug("OnRecievedData-->"+ result); Buffer.BlockCopy(recvBuf, 0, receiveBytes, 0, result); //UnityEngine.Main.Debug("OnRecievedData-->2"); m_RecvQueue.Push(receiveBytes); } } } else { Thread.Sleep(10); } } catch (SocketException ee) { #if DEBUG if (ee.NativeErrorCode == 10054) { UnityEngine.Debug.Log("无法连接到远程服务器"); } else { UnityEngine.Debug.Log("OnRecievedData-->" + ee.ToString()); } #endif NetError(); return; } } }
private void InputConsumer() { while (this._isRunning) { string cmd = Console.ReadLine(); INPUT_QUEUE.Push(cmd); if (cmd == "exit") { break; } Thread.Sleep(10); } }
private void DoReceiveInThread() { EndPoint remotePoint = IPUtility.GetIPEndPointAny(AddressFamily.InterNetwork, 0); int cnt = currentSocket.ReceiveFrom(recvBufferTemp, recvBufferTemp.Length, SocketFlags.None, ref remotePoint); if (cnt > 0) { if (!remoteEndPoint.Equals(remotePoint)) { Debuger.LogError("收到非目标服务器的数据!"); return; } byte[] dst = new byte[cnt]; Buffer.BlockCopy(recvBufferTemp, 0, dst, 0, cnt); recvBuffQueue.Push(dst); } }
void ReceiveCallback(IAsyncResult ar) { Byte[] data = (mIPEndPoint == null) ? mUdpClient.Receive(ref mIPEndPoint) : mUdpClient.EndReceive(ar, ref mIPEndPoint); if (null != data) { // push udp packet to switch queue. mRecvQueue.Push(data); } if (mUdpClient != null) { // try to receive again. mUdpClient.BeginReceive(ReceiveCallback, this); } }
//====================================================================== //接收数据 //====================================================================== protected void DoReceiveInThread() { //子线程 this.LogVerbose(); bool result = false; try { EndPoint remotePoint = IPUtils.GetIPEndPointAny(AddressFamily.InterNetwork, 0); int cnt = m_socket.ReceiveFrom(m_RecvBufferTemp, m_RecvBufferTemp.Length, SocketFlags.None, ref remotePoint); if (cnt > 0) { if (!RemoteEndPoint.Equals(remotePoint)) { Debuger.LogVerbose("收到非目标服务器的数据!"); return; } m_bufferReceive.Attach(m_RecvBufferTemp, cnt); byte[] m_32b = new byte[4]; m_bufferReceive.ReadBytes(m_32b, 0, 4); uint sid = BitConverter.ToUInt32(m_32b, 0); if (sid == 0) { //Session过期了 HandleServerError((int)NetErrorCode.SessionExpire); return; } byte[] dst = new byte[cnt]; Buffer.BlockCopy(m_RecvBufferTemp, 0, dst, 0, cnt); m_RecvBufQueue.Push(dst); } } catch (Exception ex) { this.LogWarning("接收数据出错:{0}", ex.Message); onReceiveError.InvokeSafe(this, (int)NetErrorCode.UnkownError, ex.Message); } }
/// <summary> /// 返回包的总长度 /// </summary> /// <param name="buffer"></param> /// <param name="length"></param> /// <returns></returns> public int DetectPacket(Byte[] buffer, int length) { int usedSize = 0; while (length > 0) { int packetLen = GetPacketLen(buffer, usedSize, length); if (0 == packetLen || packetLen > length) { break; } byte[] bytes = new byte[packetLen]; Array.Copy(buffer, usedSize, bytes, 0, packetLen); _recvQueue.Push(bytes); usedSize += packetLen; length -= packetLen; } return(usedSize); }
void ReceiveCallback(IAsyncResult ar) { Byte[] data = null; try { data = (mIPEndPoint == null) ? m_UdpClient.Receive(ref mIPEndPoint) : m_UdpClient.EndReceive(ar, ref mIPEndPoint); } catch (SocketException ee) { #if DEBUG if (ee.NativeErrorCode == 10054) { Console.WriteLine("无法连接到远程服务器"); } else { Console.WriteLine(ee.ToString()); } #endif this.Status = ClientSessionStatus.ConnectFail; var e = Event; if (e != null) { e(UdpClientEvents.ConnectFail, null); } return; } if (null != data) { // push udp packet to switch queue. m_RecvQueue.Push(data); } if (m_UdpClient != null) { // try to receive again. m_UdpClient.BeginReceive(ReceiveCallback, this); } }
private void E_Completed(object sender, SocketAsyncEventArgs e) { if (e.LastOperation == SocketAsyncOperation.ReceiveFrom) { #if DEV uint index = 0, key = 0; if (IsHandshake(e.Buffer, 0, e.BytesTransferred, out index, out key)) { IRQLog.AppLog.Log(index.ToString() + ",收到数据"); } #endif mRecvQueue.Push(e); //唯一一个Push的地方 m_DataReceived.Set(); //唯一一个Set的地方,在UpdateRepeatedly的第一行使用。 m_UdpSocket.ReceiveFromAsync(PopSAE()); } else if (e.LastOperation == SocketAsyncOperation.SendTo) { PushSAE(e); //对象失效,入库 } }
private void E_Completed(object sender, SocketAsyncEventArgs e) { if (e.LastOperation == SocketAsyncOperation.ReceiveFrom) { #if DEV uint index = 0, key = 0; if (IsHandshake(e.Buffer, 0, e.BytesTransferred, out index, out key)) { IRQLog.AppLog.Log(index.ToString() + ",收到数据"); } #endif mRecvQueue.Push(e); m_wait.Set(); StartRecv(); } else if (e.LastOperation == SocketAsyncOperation.SendTo) { PushSAE(e); } }
/// <summary> /// 当接收到回调 /// </summary> /// <param name="result">结果</param> private void OnReceiveCallBack(IAsyncResult result) { try { var receiveBytes = (listenEndPoint == null) ? client.Receive(ref listenEndPoint) : client.EndReceive(result, ref listenEndPoint); if (receiveBytes == null || receiveBytes.Length <= 0) { Dispose(); return; } receiveQueue.Push(receiveBytes); client.BeginReceive(OnReceiveCallBack, null); } catch (Exception) { Dispose(); } }
//====================================================================== //接收数据 //====================================================================== public void DoReceiveInGateway(byte[] buffer, int size) { byte[] dst = new byte[size]; Buffer.BlockCopy(buffer, 0, dst, 0, size); m_RecvBufQueue.Push(dst); }
/// <summary> /// channel消息回调 /// </summary> /// <param name="conv"></param> /// <param name="bytes"></param> private void OnRecive(uint conv, byte[] bytes) { recvQueue.Push(bytes); }
public static void BeginInvoke(BaseEvent e) { PENDING_LIST.Push(e); }
void OnRecv(byte[] buf) { recvQueue_.Push(buf); }
public void ProcessServerKeyFrame(_DTO_frame_info dto) { SERVER_KEYFRAMES.Push(dto); }
void OnData(byte[] buf) { mRecvQueue.Push(buf); }
public void DoReceiveInGateway(byte[] buffer, int len) { byte[] dst = new byte[len]; Buffer.BlockCopy(buffer, 0, dst, 0, len); recvBufQueue.Push(dst); }
private static void HandleFrame(Packet packet) { SERVER_KEYFRAMES.Push((( _PACKET_BATTLE_ACMD_FRAME )packet).dto); }
void OnData(byte[] buf) { //Debug.Log("收到消息"); mRecvQueue.Push(buf); }