private void PrivateGotPacket(System.IAsyncResult result) { //Check if disposed if (sock == null) { return; } //Get the data out of this. sock.EndReceive(result); pendingAsync = null; //We'll now read in the size of the packet based on the "receiveBuffer" int sent. int size = ReadIntFromStream(receiveBuffer); //We'll now read in the remainder of the packet. byte[] buffer = new byte[size + 4]; //Copy the current receiveBuffer to this buffer. This'll allow us to have the length. receiveBuffer.CopyTo(buffer, 0); //Now, read in the remainder of the packet from the socket. sock.Receive(buffer, 4, size, SocketFlags.None); //We'll now begin listening again. PrivateBeginWaitingForPacket(); //Now, we'll convert this to a real packet we can understand. RconPacket packet = null; try { packet = RconPacket.ToPacket(buffer); //If the callback list contains this, call back. Ignore Ark's "Keep Alive" packets. if (internalCallbacks.ContainsKey(packet.id) && packet.body != "Keep Alive") { internalCallbacks[packet.id](packet); } } catch (Exception ex) { //There was an error. throw ex; } }