public unsafe MemoryStream ReadBytes(int length, bool compressed) { Check(); MemoryStream memoryStream = new MemoryStream(); if (length == -1) { length = incomingBytesUnread; } if (memoryStream.Capacity < length) { memoryStream.Capacity = length + 32; fixed(byte *data = memoryStream.GetBuffer()) { memoryStream.SetLength(memoryStream.Capacity); if (!RakNet_Native.NETRCV_ReadBytes(ptr, data, length)) { Debug.LogWarning("[RakNet] NETRCV_ReadBytes returned false"); return(null); } memoryStream.SetLength(length); return(memoryStream); } }
public bool Receive() { if (ptr == IntPtr.Zero) { return(false); } return(RakNet_Native.NET_Receive(ptr)); }
public void Close() { if (ptr != IntPtr.Zero) { RakNet_Native.NET_Close(ptr); ptr = IntPtr.Zero; } }
public unsafe byte ReadByte() { Check(); fixed(byte *data = ByteBuffer) { if (!RakNet_Native.NETRCV_ReadBytes(ptr, data, 1)) { Debug.LogWarning("[RakNet] NETRCV_ReadBytes returned false"); return(0); } return(ByteBuffer[0]); } }
public static Peer CreateServer(string ip, int port, int maxConnections) { Peer peer = new Peer(); peer.ptr = RakNet_Native.NET_Create(); if (RakNet_Native.NET_StartServer(peer.ptr, ip, port, maxConnections) == 0) { return(peer); } peer.Close(); string text = StringFromPointer(RakNet_Native.NET_LastStartupError(peer.ptr)); Debug.LogWarning("[RakNet] Couldn't create server on port " + port + " (" + text + ")"); return(null); }
private unsafe byte *Read(int size, byte *data) { Check(); if (size > ReadBuffer.Length) { throw new Exception("[RakNet] Size > ReadBuffer.Length"); } if (RakNet_Native.NETRCV_ReadBytes(ptr, data, size)) { return(data); } Debug.LogWarning("[RakNet] NETRCV_ReadBytes returned false"); return(null); }
public static Peer CreateConnection(string hostname, int port, int retries, int retryDelay, int timeout) { Peer peer = new Peer(); peer.ptr = RakNet_Native.NET_Create(); if (RakNet_Native.NET_StartClient(peer.ptr, hostname, port, retries, retryDelay * 100, timeout * 100) == 0) { Debug.Log("[RakNet] Peer created connection to " + hostname + ":" + port + " with " + retries + " retry count [delay: " + retryDelay + "] [Timeout: " + timeout + "]"); return(peer); } string text = StringFromPointer(RakNet_Native.NET_LastStartupError(peer.ptr)); Debug.LogWarning("[RakNet] Couldn't connect to server " + hostname + ":" + port + " (" + text + ")"); peer.Close(); peer = null; return(null); }
protected unsafe virtual bool Read(byte *data, int length, bool compressed) { Check(); return(RakNet_Native.NETRCV_ReadBytes(ptr, data, length)); }
public virtual void SetReadPos(int bitsOffset) { Check(); RakNet_Native.NETRCV_SetReadPointer(ptr, bitsOffset); }