static int Send(IntPtr L) { try { int count = LuaDLL.lua_gettop(L); if (count == 2 && TypeChecker.CheckTypes <string>(L, 2)) { BestHTTP.WebSocket.WebSocketResponse obj = (BestHTTP.WebSocket.WebSocketResponse)ToLua.CheckObject(L, 1, typeof(BestHTTP.WebSocket.WebSocketResponse)); string arg0 = ToLua.ToString(L, 2); obj.Send(arg0); return(0); } else if (count == 2 && TypeChecker.CheckTypes <byte[]>(L, 2)) { BestHTTP.WebSocket.WebSocketResponse obj = (BestHTTP.WebSocket.WebSocketResponse)ToLua.CheckObject(L, 1, typeof(BestHTTP.WebSocket.WebSocketResponse)); byte[] arg0 = ToLua.CheckByteBuffer(L, 2); obj.Send(arg0); return(0); } else if (count == 2 && TypeChecker.CheckTypes <BestHTTP.WebSocket.Frames.WebSocketFrame>(L, 2)) { BestHTTP.WebSocket.WebSocketResponse obj = (BestHTTP.WebSocket.WebSocketResponse)ToLua.CheckObject(L, 1, typeof(BestHTTP.WebSocket.WebSocketResponse)); BestHTTP.WebSocket.Frames.WebSocketFrame arg0 = (BestHTTP.WebSocket.Frames.WebSocketFrame)ToLua.ToObject(L, 2); obj.Send(arg0); return(0); } else if (count == 4) { BestHTTP.WebSocket.WebSocketResponse obj = (BestHTTP.WebSocket.WebSocketResponse)ToLua.CheckObject(L, 1, typeof(BestHTTP.WebSocket.WebSocketResponse)); byte[] arg0 = ToLua.CheckByteBuffer(L, 2); ulong arg1 = LuaDLL.tolua_checkuint64(L, 3); ulong arg2 = LuaDLL.tolua_checkuint64(L, 4); obj.Send(arg0, arg1, arg2); return(0); } else { return(LuaDLL.luaL_throw(L, "invalid arguments to method: BestHTTP.WebSocket.WebSocketResponse.Send")); } } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
static int Send(IntPtr L) { try { int count = LuaDLL.lua_gettop(L); if (count == 2 && TypeChecker.CheckTypes(L, 1, typeof(BestHTTP.WebSocket.WebSocket), typeof(BestHTTP.WebSocket.Frames.WebSocketFrame))) { BestHTTP.WebSocket.WebSocket obj = (BestHTTP.WebSocket.WebSocket)ToLua.ToObject(L, 1); BestHTTP.WebSocket.Frames.WebSocketFrame arg0 = (BestHTTP.WebSocket.Frames.WebSocketFrame)ToLua.ToObject(L, 2); obj.Send(arg0); return(0); } else if (count == 2 && TypeChecker.CheckTypes(L, 1, typeof(BestHTTP.WebSocket.WebSocket), typeof(byte[]))) { BestHTTP.WebSocket.WebSocket obj = (BestHTTP.WebSocket.WebSocket)ToLua.ToObject(L, 1); byte[] arg0 = ToLua.CheckByteBuffer(L, 2); obj.Send(arg0); return(0); } else if (count == 2 && TypeChecker.CheckTypes(L, 1, typeof(BestHTTP.WebSocket.WebSocket), typeof(string))) { BestHTTP.WebSocket.WebSocket obj = (BestHTTP.WebSocket.WebSocket)ToLua.ToObject(L, 1); string arg0 = ToLua.ToString(L, 2); obj.Send(arg0); return(0); } else if (count == 4 && TypeChecker.CheckTypes(L, 1, typeof(BestHTTP.WebSocket.WebSocket), typeof(byte[]), typeof(ulong), typeof(ulong))) { BestHTTP.WebSocket.WebSocket obj = (BestHTTP.WebSocket.WebSocket)ToLua.ToObject(L, 1); byte[] arg0 = ToLua.CheckByteBuffer(L, 2); ulong arg1 = (ulong)LuaDLL.lua_tonumber(L, 3); ulong arg2 = (ulong)LuaDLL.lua_tonumber(L, 4); obj.Send(arg0, arg1, arg2); return(0); } else { return(LuaDLL.luaL_throw(L, "invalid arguments to method: BestHTTP.WebSocket.WebSocket.Send")); } } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
/// <summary> /// It will send the given frame to the server. /// </summary> public void Send(WebSocketFrame frame) { if (IsOpen) webSocket.Send(frame); }
public WebSocketFrame[] Fragment(ushort maxFragmentSize) { if (this.Data == null) return null; // All control frames MUST have a payload length of 125 bytes or less and MUST NOT be fragmented. if (this.Type != WebSocketFrameTypes.Binary && this.Type != WebSocketFrameTypes.Text) return null; if (this.Data.Length <= maxFragmentSize) return null; this.IsFinal = false; // Clear final bit from the header flags this.Header &= 0x7F; // One chunk will remain in this fragment, so we have to allocate one less int count = (this.Data.Length / maxFragmentSize) + (this.Data.Length % maxFragmentSize) - 1; WebSocketFrame[] fragments = new WebSocketFrame[count]; // Skip one chunk, for the current one UInt64 pos = maxFragmentSize; while (pos < (UInt64)this.Data.Length) { UInt64 chunkLength = Math.Min(maxFragmentSize, (UInt64)this.Data.Length - pos); fragments[fragments.Length - count--] = new WebSocketFrame(null, WebSocketFrameTypes.Continuation, this.Data, pos, chunkLength, pos + chunkLength >= (UInt64)this.Data.Length, false); pos += chunkLength; } byte[] newData = new byte[maxFragmentSize]; Array.Copy(this.Data, 0, newData, 0, maxFragmentSize); this.Data = newData; return fragments; }
/// <summary> /// IExtension implementation to be able to compress the data hold in the writer. /// </summary> public byte[] Encode(WebSocketFrame writer) { if (writer.Data == null) return WebSocketFrame.NoData; // Is compressing enabled for this frame? If so, compress it. if ((writer.Header & 0x40) != 0) return Compress(writer.Data); else return writer.Data; }
/// <summary> /// IExtension implementation to set the Rsv1 flag in the header if we are we will want to compress the data /// in the writer. /// </summary> public byte GetFrameHeader(WebSocketFrame writer, byte inFlag) { // http://tools.ietf.org/html/rfc7692#section-7.2.3.1 // the RSV1 bit is set only on the first frame. if ((writer.Type == WebSocketFrameTypes.Binary || writer.Type == WebSocketFrameTypes.Text) && writer.Data != null && writer.Data.Length >= this.MinimumDataLegthToCompress) return (byte)(inFlag | 0x40); else return inFlag; }
/// <summary> /// It will send the given frame to the server. /// </summary> public void Send(WebSocketFrame frame) { if (frame == null) throw new ArgumentNullException("frame is null!"); if (closed) return; byte[] rawData = frame.Get(); lock (SendLock) { Stream.Write(rawData, 0, rawData.Length); Stream.Flush(); if (frame.Type == WebSocketFrameTypes.ConnectionClose) closeSent = true; } }
/// <summary> /// Will send count bytes from a byte array, starting from offset. /// </summary> public void Send(byte[] data, ulong offset, ulong count) { if (data == null) throw new ArgumentNullException("data must not be null!"); if (offset + count > (ulong)data.Length) throw new ArgumentOutOfRangeException("offset + count >= data.Length"); WebSocketFrame frame = new WebSocketFrame(this.WebSocket, WebSocketFrameTypes.Binary, data, offset, count, true, true); if (frame.Data != null && frame.Data.Length > this.MaxFragmentSize) { WebSocketFrame[] additionalFrames = frame.Fragment(this.MaxFragmentSize); lock (SendLock) { Send(frame); if (additionalFrames != null) for (int i = 0; i < additionalFrames.Length; ++i) Send(additionalFrames[i]); } } else Send(frame); }
/// <summary> /// It will send the given data to the server in one frame. /// </summary> public void Send(byte[] data) { if (data == null) throw new ArgumentNullException("data must not be null!"); WebSocketFrame frame = new WebSocketFrame(this.WebSocket, WebSocketFrameTypes.Binary, data); if (frame.Data != null && frame.Data.Length > this.MaxFragmentSize) { WebSocketFrame[] additionalFrames = frame.Fragment(this.MaxFragmentSize); lock(SendLock) { Send(frame); if (additionalFrames != null) for (int i = 0; i < additionalFrames.Length; ++i) Send(additionalFrames[i]); } } else Send(frame); }