Exemplo n.º 1
0
        public void SendData(Client?cl, Viewer.DataType type, Viewer.IWalkerSimMessage data)
        {
            if (cl == null)
            {
                Broadcast(type, data);
                return;
            }

            MemoryStream streamBody = new MemoryStream();

            data.Serialize(streamBody);

            Viewer.Header header = new Viewer.Header();
            header.type = (int)type;
            header.len  = (int)streamBody.Length;

            MemoryStream streamHeader = new MemoryStream();

            header.Serialize(streamHeader);

            try
            {
                Send(cl, streamHeader.GetBuffer(), (int)streamHeader.Length);
                Send(cl, streamBody.GetBuffer(), (int)streamBody.Length);
            }
            catch (Exception ex)
            {
                cl.disconnected = true;

#if DEBUG
                Log.Out("ViewServer::SendData caused exception");
                Log.Exception(ex);
#endif
            }
        }
Exemplo n.º 2
0
        public void Broadcast(Viewer.DataType type, Viewer.IWalkerSimMessage data)
        {
            if (_clients.Count == 0)
            {
                return;
            }

            MemoryStream streamBody = new MemoryStream();

            data.Serialize(streamBody);

            Viewer.Header header = new Viewer.Header();
            header.type = (int)type;
            header.len  = (int)streamBody.Length;

            MemoryStream streamHeader = new MemoryStream();

            header.Serialize(streamHeader);

            try
            {
                //Log.Out("Sending Packet: {0}, bytes: {1}", header.type, header.len);
                foreach (var client in _clients)
                {
                    //client.sock.Send(streamHeader.GetBuffer(), (int)streamHeader.Length, SocketFlags.None);
                    Send(client, streamHeader.GetBuffer(), (int)streamHeader.Length);
                    //client.sock.Send(streamBody.GetBuffer(), (int)streamBody.Length, SocketFlags.None);
                    Send(client, streamBody.GetBuffer(), (int)streamBody.Length);
                }
            }
            catch (Exception)
            {
            }
        }
Exemplo n.º 3
0
        public void Broadcast(Viewer.DataType type, Viewer.IWalkerSimMessage data)
        {
            if (_clients.Count == 0)
            {
                return;
            }

            var streamBody = new MemoryStream();

            data.Serialize(streamBody);

            var header = new Viewer.Header();

            header.type = (int)type;
            header.len  = (int)streamBody.Length;

            MemoryStream streamHeader = new MemoryStream();

            header.Serialize(streamHeader);

            try
            {
                lock (_clients)
                {
                    //Log.Out("Sending Packet: {0}, bytes: {1}", type.ToString(), header.len);
                    foreach (var client in _clients)
                    {
                        Send(client, streamHeader.GetBuffer(), (int)streamHeader.Length);
                        Send(client, streamBody.GetBuffer(), (int)streamBody.Length);
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Out("ViewServer::Broadcast caused exception");
                Log.Exception(ex);
            }
        }