void DispatchSend() { if (socket == null) { return; } try { if (socket.Poll(0, SelectMode.SelectWrite)) { byte[] buffer = new byte[PACKET_SIZE]; int sendSize = sendQueue.Dequeue(ref buffer, buffer.Length); while (sendSize > 0) { socket.Send(buffer, sendSize, SocketFlags.None); sendSize = sendQueue.Dequeue(ref buffer, buffer.Length); } } } catch { if (networkStateHandler != null) { NetworkState state = new NetworkState(); state.type = NetEventType.SendError; state.result = NetEventResult.Failure; networkStateHandler(this, state); } } }
void DispatchSend() { if (m_socket == null) { return; } try { // 송신 처리. if (m_socket.Poll(0, SelectMode.SelectWrite)) { byte[] buffer = new byte[m_packetSize]; int sendSize = m_sendQueue.Dequeue(ref buffer, buffer.Length); while (sendSize > 0) { m_socket.SendTo(buffer, sendSize, SocketFlags.None, m_localEndPoint); sendSize = m_sendQueue.Dequeue(ref buffer, buffer.Length); } } } catch { return; } }
void DispatchSend() { if (m_socket == null) { return; } try { // 송신 처리. //if (m_socket.Poll(0, SelectMode.SelectWrite)) { byte[] buffer = new byte[m_packetSize]; int sendSize = m_sendQueue.Dequeue(ref buffer, buffer.Length); while (sendSize > 0) { foreach (Socket socket in m_socket) { socket.Send(buffer, sendSize, SocketFlags.None); } sendSize = m_sendQueue.Dequeue(ref buffer, buffer.Length); } //} } catch { if (m_handler != null) { NetEventState state = new NetEventState(); state.type = NetEventType.SendError; state.result = NetEventResult.Failure; m_handler(state); } } }
void DispatchSend() { if (m_socket == null) { return; } try { // 송신 처리. if (m_socket.Poll(0, SelectMode.SelectWrite)) { byte[] buffer = new byte[m_packetSize]; int sendSize = m_sendQueue.Dequeue(ref buffer, buffer.Length); while (sendSize > 0) { int res = m_socket.Send(buffer, sendSize, SocketFlags.None); sendSize = m_sendQueue.Dequeue(ref buffer, buffer.Length); //Debug.Log("Send udp data." + res); } } } catch { return; } }
//スレッド側の送信処理 void DispatchSend() { //送信処理 if (m_socket.Poll(0, SelectMode.SelectWrite)) { byte[] buffer = new byte[s_mtu]; int sendSize = m_sendQueue.Dequeue(ref buffer, buffer.Length); while (sendSize > 0) { m_socket.Send(buffer, sendSize, SocketFlags.None); sendSize = m_sendQueue.Dequeue(ref buffer, buffer.Length); } } }
public byte[] CharaWorkExp(Socket sender) { if (PacketQueue == null || PacketQueue.Count == 0) { Inventory.Update(sender); Queue <short> jobLevel = new Queue <short>(); Queue <short> jobLevelCap = new Queue <short>(); int count = 0; foreach (var item in Jobs) { count++; if (count > 52) { break; } Job job = item.Value; jobLevel.Enqueue(job.Level); jobLevelCap.Enqueue(job.LevelCap); } WorkProperties property = new WorkProperties(sender, Id, @"charaWork/exp"); property.Add("charaWork.battleSave.skillLevel", jobLevel); property.Add("charaWork.battleSave.skillLevelCap", jobLevelCap, true); PacketQueue = property.PacketQueue; } return(PacketQueue.Dequeue()); }
private void Send() { try { while (Socket.Connected) { if (this.clientAbort.WaitOne(10) || Worker.Singleton.ServerShutdown.WaitOne(10)) { return; } while (PacketQueue.Count > 0) { var p = PacketQueue.Dequeue(); using (var ms = new MemoryStream()) { using (var bw = new BinaryWriter(ms)) { p.WriteTo(bw); Logging.Debug(ms.ToArray().Hexdump()); Socket.Send(ms.ToArray()); } } } } } catch { // nevermind } this.clientAbort.Set(); }
void Update() { // 서버로부터 받기 if (m_pcFromServer.GetPacketCount() > 0) { PacketQueue queue = m_pcFromServer.GetBuffer(); Socket sock; int count = queue.Count; for (int i = 0; i < count; i++) { queue.Dequeue(out sock, ref m_recvBuffer, m_recvBuffer.Length); ReceivePacket(m_notiServer, sock, m_recvBuffer); } } // 게스트(또는 호스트)로부터 받기 if (m_pcFromP2P.GetPacketCount() > 0) { PacketQueue queue = m_pcFromP2P.GetBuffer(); Socket sock; int count = queue.Count; for (int i = 0; i < count; i++) { queue.Dequeue(out sock, ref m_recvBuffer, m_recvBuffer.Length); ReceivePacket(m_notiP2P, sock, m_recvBuffer); } } }
public void OnData() { try { PacketReader packet = null; if (PacketQueue.Count > 0) { packet = (PacketReader)PacketQueue.Dequeue(); } else { packet = new PacketReader(ReceiveBuffer); } PacketLog.WritePacket(clientSocket.RemoteEndPoint.ToString(), null, packet); if (Enum.IsDefined(typeof(Opcodes), packet.Opcode)) { PacketManager.InvokeHandler(ref packet, this, (Opcodes)packet.Opcode); } else { Log.outDebug("Received unknown opcode 0x{0:X} ({0}) from AcountId:{1}", (ushort)packet.Opcode, GetAccountId()); } } catch (Exception ex) { Log.outException(ex); } }
//수신처리 public int Receive(ref byte[] buffer, int size) { if (receiveQueue == null) return 0; return receiveQueue.Dequeue(ref buffer, size); }
private void ProcessStanzas() { while (_processStream) { var packet = _stanzaQueue.Dequeue(); OnStanzaReceived(packet); } }
public int Receive(ref byte[] buffer, int size) { if (m_sendQueue == null) { return(0); } return(m_recvQueue.Dequeue(ref buffer, size)); }
public int TryParseNextIncomingPacket(byte[] outBuffer, out byte channelId) { if (_incomingDelayQueue.Count > 0 && _incomingDelayQueue.Peek().timestamp <= GetNow()) { var entry = _incomingDelayQueue.Dequeue(); _internalBuffer.ReceiveRawData(entry.data, entry.length); } return(_internalBuffer.TryParseNextIncomingPacket(outBuffer, out channelId)); }
void DispatchSend() { if (m_socket == null) { return; } try { // 송신처리. if (m_socket.Poll(0, SelectMode.SelectWrite)) { byte[] buffer = new byte[m_packetSize]; int sendSize = m_sendQueue.Dequeue(ref buffer, buffer.Length); while (sendSize > 0) { try { int sendResult = m_socket.Send(buffer, sendSize, SocketFlags.None); if (sendResult < 0) { Debug.Log("Transport send error send size:" + sendResult); } } catch (SocketException e) { Debug.Log("Transport send error:" + e.Message); if (m_handler != null) { NetEventState state = new NetEventState(); state.node = m_nodeId; state.type = NetEventType.SendError; state.result = NetEventResult.Failure; m_handler(this, state); } } sendSize = m_sendQueue.Dequeue(ref buffer, buffer.Length); } } } catch { return; } }
// receive public void ReceiveFromClient() { Console.WriteLine("Receive Threading start"); while (true) { int count = receiveQueue.Count; for (int i = 0; i < count; i++) { int receiveSize = 0; receiveSize = receiveQueue.Dequeue(ref receiveBuffer, receiveBuffer.Length); Socket clientSocket; lock (lockIndexQueue) { if (indexClientQueue.Count == 0) { continue; } clientSocket = indexClientQueue.Dequeue(); } // packet precess if (receiveSize > 0) { byte[] message = new byte[receiveSize]; Array.Copy(receiveBuffer, message, receiveSize); int packetID; byte[] packetData; // packet seperate -> header / data SeperatePacket(message, out packetID, out packetData); ReceiveNotifier notifier; try { // use notifier notifierForServer.TryGetValue(packetID, out notifier); activateMethodName = notifier.Method.ToString(); notifier(clientSocket, packetData); } catch (NullReferenceException e) { Console.WriteLine(e.Message); Console.WriteLine("Server : Null Reference Exception - On Receive (use notifier)"); } } } } }
public void Update() { lock (PacketQueue) { while (PacketQueue.Count > 0) { Packet oPacket = PacketQueue.Dequeue(); Process(oPacket); } } }
//서버측 송신처리(스레드 작업) void DispatchSend() { try { if(ClientSocket.Poll(0, SelectMode.SelectWrite)) { byte[] buffer = new byte[BUFFERSIZE]; int sendSize = sendQueue.Dequeue(ref buffer, buffer.Length); while(sendSize > 0) { ClientSocket.Send(buffer, sendSize, SocketFlags.None); sendSize = sendQueue.Dequeue(ref buffer, buffer.Length); } } } catch { return; } }
void DispatchSend() { try{ if (m_socket.Poll(0, SelectMode.SelectWrite)) { byte[] buffer = new byte[buffer_size]; int sendsize = m_sendQueue.Dequeue(ref buffer, buffer.Length); while (sendsize > 0) { m_socket.Send(buffer, sendsize, SocketFlags.None); sendsize = m_sendQueue.Dequeue(ref buffer, buffer.Length); } } } catch { return; } }
public void DispatchSend() { try { if (mSocketForClient.Poll(0, SelectMode.SelectWrite)) { byte[] buffer = new byte[Config.MTU]; int sendSize = mSendQueue.Dequeue(ref buffer, buffer.Length); while (sendSize > 0) { mSocketForClient.Send(buffer, sendSize, SocketFlags.None); sendSize = mSendQueue.Dequeue(ref buffer, buffer.Length); } } } catch { return; } }
// 스레드의 송수신처리. void DispatchSend() { try { // 송신처리. if (m_socket.Poll(0, SelectMode.SelectWrite)) { byte[] buffer = new byte[s_mtu]; int sendSize = m_sendQueue.Dequeue(ref buffer, buffer.Length); while (sendSize > 0) { IPEndPoint endpoint = new IPEndPoint(IPAddress.Parse(m_address), m_port); m_socket.SendTo(buffer, sendSize, SocketFlags.None, endpoint); sendSize = m_sendQueue.Dequeue(ref buffer, buffer.Length); } } } catch { return; } }
//수신처리 public int GetFromQueue(ref byte[] buffer, int size) { if (mRecvQueue == null) { Console.WriteLine("Receive ERROR ryu."); return(0); } int tResult = mRecvQueue.Dequeue(ref buffer, size); return(tResult); }
public int GetFromQueue(ref byte[] buffer, int size) { if (mRecvQueue == null) { Debug.Log("Receive ERROR"); return(0); } int tResult = mRecvQueue.Dequeue(ref buffer, size); return(tResult); }
// 스레트 측 송신처리. void DispatchSend() { try { // 송신처리. if (socket.Poll(0, SelectMode.SelectWrite)) { byte[] buffer = new byte[s_mtu]; int sendSize = sendQueue.Dequeue(ref buffer, buffer.Length); while (sendSize > 0) { socket.Send(buffer, sendSize, SocketFlags.None); sendSize = sendQueue.Dequeue(ref buffer, buffer.Length); } } } catch { return; } }
/// <summary> /// 送信用キューに溜まっているパケットを送信する /// 接続されていない場合は実行されない /// </summary> private void SendQueueDispach() { if (sock.Poll(0, SelectMode.SelectWrite)) { int sendSize;//送信するパケットのサイズ //送信バッファからパケットを取り出す while ((sendSize = sendQueue.Dequeue(ref packet)) > 0) { //パケットの取り出しに成功したらそのパケットを送信する sock.Send(packet, sendSize, SocketFlags.None); Array.Clear(packet, 0, packet.Length); } } }
/// <summary> /// 接続完了後に呼び出し可能 /// 受信用キューからパケットデータを取得する /// 取得出来なかった場合は-1を返す /// </summary> /// <returns>パケットデータサイズ</returns> /// <exception cref="InvalidOperationException">接続が確立されていない場合</exception> public int Receive(ref byte[] data) { if (!IsConnected) { throw new InvalidOperationException("接続が完了していないためReceiveを呼び出せません"); } //キューから取り出すパケットサイズが0より上なら if (recvQueue.PeekSize() > 0) { return(recvQueue.Dequeue(ref data)); } else { return(-1); } }
private void SendNotificationIfAvailable() { Notification notification = null; lock (PacketQueue) { if (!IsAlreadySendingPacket && PacketQueue.Count > 0) { notification = PacketQueue.Dequeue(); IsAlreadySendingPacket = true; } } if (notification != null) { SendNotificationUnsafe(notification); } }
// receive public void ReceiveFromClient() { int count = receiveQueue.Count; for (int i = 0; i < count; i++) { int receiveSize = 0; receiveSize = receiveQueue.Dequeue(ref receiveBuffer, receiveBuffer.Length); Socket clientSocket; lock ( lockReceiveQueue ) { clientSocket = indexClientQueue.Dequeue(); } // packet precess if (receiveSize > 0) { byte[] message = new byte[receiveSize]; Array.Copy(receiveBuffer, message, receiveSize); int packetID; byte[] packetData; // packet seperate -> header / data SeperatePacket(message, out packetID, out packetData); ReceiveNotifier notifier; // use notifier try { notifierForServer.TryGetValue(packetID, out notifier); notifier(clientSocket, packetData); } catch (NullReferenceException e) { Debug.Log(e.Message); Debug.Log("Server : Null Reference Exception - On Receive (use notifier)"); } } } }
private void ReadNextPacket() { if (m_position >= Length) { throw new System.IO.EndOfStreamException(); } if (m_disposed) { return; } AVPacket packet; bool retry = false; do { while (PacketQueue.Count == 0) { m_file.EnqueueNextPacket(); } packet = PacketQueue.Dequeue(); try { retry = !DecodePacket(ref packet); } finally { FFmpeg.av_free_packet(ref packet); } } while (retry); m_rawDts = packet.dts; m_rawPts = packet.pts; }
// This function works on a thread. private void GetPacketFromQueue() { while (trdGetPacketFromQueueAct) { RawCapture rawCapture; Packet packet = null; if (PacketQueue.Count == 0) // the Queue doesn't have packets. { if (PcapFileEOF == true) { trdGetPacketFromQueueAct = false; break; } else { continue; } } lock (PacketQueueLock) { rawCapture = PacketQueue.Dequeue(); } try { packet = Packet.ParsePacket(rawCapture.LinkLayerType, rawCapture.Data); } catch { continue; } LastPacketArrivalTime = rawCapture.Timeval.Date.ToLocalTime().ToString(); //Hydar // Packet tmpTcpPacket = null; // tmpTcpPacket = (packet as TcpPacket); //else if (packet is EthernetPacket) //{ // //协议数据区(TCP/IP协议包数据区,包括IP协议数据及TCP协议数据) // byte[] tmpBuf = new byte[packet.Bytes.Length - 8]; // //复制实际TCP/IP数据块 // Array.Copy(packet.Bytes, 8, tmpBuf, 0, tmpBuf.Length); // MemoryStream tmpMs = new MemoryStream(); // //将原来的以太包头作为目标TCP/IP数据包的以太头 // tmpMs.Write(packet.Header, 0, packet.Header.Length); // //将实际TCP/IP数据包写入目标TCP/IP数据包中,跟在以太包头后面,成为一个新的TCP/IP数据包 // tmpMs.Write(tmpBuf, 0, tmpBuf.Length); // try // { // //尝试创建新的TCP/IP数据包对象, // //第一个参数为以太头长度,第二个为数据包数据块 // tmpTcpPacket = Packet.ParsePacket(rawCapture.LinkLayerType, tmpMs.ToArray()); // } // catch { tmpTcpPacket = null; } // tmpMs.Dispose(); //} // SIP、RTP Packet Analyze and handle them if (Status == EnumStatus.Monitor) { SIPTrace.Handler(packet); } // POP3、SMTP、IMAP Packet Analyze MailTrace.Trace(packet); HttpMail.Trace(packet, this); // Log SSL Keys SSLTrace.Trace(packet, this); // Push pakcet to List<IPTrace> UpdateListIPTrace(rawCapture); if (this.Status == EnumStatus.OpenFile) { mReadFileProgressBar.Increment(rawCapture.Data.Length); } } }
// public int Receive(ref byte[] buffer, int size) { return(m_recvQueue.Dequeue(ref buffer, size)); }