Example #1
0
        public override async Task Respond(MessageContainer data)
        {
            switch (dataFormat)
            {
            case DataFormat.Text:
                await instance.Send(data.SessionId, data.GetText());

                break;

            case DataFormat.Json:
                await instance.Send(data.SessionId, data.GetJson());

                break;
            }
        }
        public CommonNetwork Login(User user)
        {
            PacketData packet = new PacketData();

            packet.packetNum = (int)PacketNumConstants.PacketNum.LOGIN;
            Dictionary <string, object> data = new Dictionary <string, object>();

            data.Add("userId", user.userId);
            data.Add("osType", user.osType);
            data.Add("guestMode", user.guestMode);

            packet.data = data;

            socket.Send(packet);

            return(this);
        }
Example #3
0
        /// <summary>
        /// Creates web socket message from model and sends to specified client
        /// </summary>
        public static void Send <TModel>(this SocketBase socket, TModel model, IModelWriter writer) where TModel : ISerializableModel
        {
            WebSocketMessage message = new WebSocketMessage
            {
                OpCode  = SocketOpCode.UTF8,
                Content = new MemoryStream(Encoding.UTF8.GetBytes(writer.Serialize(model)))
            };

            socket.Send(_writer.Create(message).Result);
        }
Example #4
0
        public void Write([NotNull] SocketBase s)
        {
            int size = 4 + 1 + m_addr.Length + 1; // event + len(addr) + addr + flag

            if (m_flag == ValueInteger)
            {
                size += 4;
            }
            else if (m_flag == ValueChannel)
            {
                size += s_sizeOfIntPtr;
            }

            int pos = 0;

            ByteArraySegment buffer = new byte[size];

            buffer.PutInteger(Endianness.Little, (int)m_monitorEvent, pos);
            pos          += 4;
            buffer[pos++] = (byte)m_addr.Length;

            // was not here originally

            buffer.PutString(m_addr, pos);
            pos += m_addr.Length;

            buffer[pos++] = ((byte)m_flag);
            if (m_flag == ValueInteger)
            {
                buffer.PutInteger(Endianness.Little, (int)m_arg, pos);
            }
            else if (m_flag == ValueChannel)
            {
                GCHandle handle = GCHandle.Alloc(m_arg, GCHandleType.Weak);

                if (s_sizeOfIntPtr == 4)
                {
                    buffer.PutInteger(Endianness.Little, GCHandle.ToIntPtr(handle).ToInt32(), pos);
                }
                else
                {
                    buffer.PutLong(Endianness.Little, GCHandle.ToIntPtr(handle).ToInt64(), pos);
                }
            }

            var msg = new Msg();

            msg.InitGC((byte[])buffer, buffer.Size);
            s.Send(ref msg, SendReceiveOptions.None);
        }
Example #5
0
 public virtual void Send(ref Msg msg, SendReceiveOptions options)
 {
     m_socketHandle.Send(ref msg, options);
 }