public static void Send(this Socket socket, string text) { Frame frame = new Frame(); frame.Init(Encoding.UTF8.GetBytes(text)); socket.TrySend(ref frame, Timeout.InfiniteTimeSpan); frame.Close(); }
public bool TryReceive(ref Frame frame) { if (State != ReceiveState.MessageReady) { return(false); } frame.Close(); frame.Init(m_data); Handle(ReceiveAction.Fetched); return(true); }
public bool TrySend(ref Frame frame) { if (State != SendState.Ready) { return(false); } int payloadIndex; byte[] data; if (frame.Size <= 255) { data = new byte[2 + frame.Size]; data[0] = 0; // More is not supported data[1] = (byte)frame.Size; payloadIndex = 2; } else { data = new byte[9 + frame.Size]; data[0] = 2; // More is not supported NetworkOrderBitsConverter.PutInt64((long)frame.Size, data, 1); payloadIndex = 9; } frame.CopyTo(data, payloadIndex); frame.Close(); frame.Init(); State = SendState.Sending; SendData(data); return(true); }