示例#1
0
        private void AddNewClient(Socket socket)
        {
            if ((Options & Utf8TcpServerOptions.SingleClientOnly) != 0)
            {
                lock (m_PeerListLock)
                {
                    foreach (var pp in m_PeerList)
                    {
                        pp.Disconnect();
                    }
                }
            }

            Utf8TcpPeer peer = new Utf8TcpPeer(this, socket);

            lock (m_PeerListLock)
            {
                m_PeerList.Add(peer);
                peer.ConnectionClosed += OnPeerDisconnected;
                peer.DataReceived     += OnPeerDataReceived;
            }


            if (ClientConnected != null)
            {
                Utf8TcpPeerEventArgs args = new Utf8TcpPeerEventArgs(peer);
                ClientConnected(this, args);
            }

            peer.Start();
        }
示例#2
0
		private void SendHttp(Utf8TcpPeer peer, string responseCode, string contentType, byte[] data, params string[] extraHeaders)
		{
			peer.Send("HTTP/1.0 {0}", responseCode);
			peer.Send("Server: moonsharp-remote-debugger/{0}", VERSION);
			peer.Send("Content-Type: {0}", contentType);
			peer.Send("Content-Length: {0}", data.Length);
			peer.Send("Connection: close");
			peer.Send("Cache-Control: max-age=0, no-cache");

			foreach (string h in extraHeaders)
				peer.Send(h);

			peer.Send("");
			peer.SendBinary(data);
		}
示例#3
0
        private void ExecHttpRequest(Utf8TcpPeer peer, List <string> httpdata)
        {
            try
            {
                if (Authenticator != null)
                {
                    string authstr    = httpdata.FirstOrDefault(s => s.StartsWith("Authorization:"));
                    bool   authorized = false;

                    if (authstr != null)
                    {
                        string user, password;
                        ParseAuthenticationString(authstr, out user, out password);
                        authorized = Authenticator(user, password);
                    }

                    if (!authorized)
                    {
                        SendHttp(peer, "401 Not Authorized", "text/html", ERROR_401, "WWW-Authenticate: Basic realm=\"moonsharp-remote-debugger\"");
                        return;
                    }
                }

                HttpResource res = GetResourceFromPath(httpdata[0]);

                if (res == null)
                {
                    SendHttp(peer, "404 Not Found", "text/html", ERROR_404);
                }
                else
                {
                    SendHttp(peer, "200 OK", res.GetContentTypeString(), res.Data);
                }
            }
            catch (Exception ex)
            {
                m_Server.Logger(ex.Message);

                try
                {
                    SendHttp(peer, "500 Internal Server Error", "text/html", ERROR_500);
                }
                catch (Exception ex2)
                {
                    m_Server.Logger(ex2.Message);
                }
            }
        }
示例#4
0
        private void SendHttp(Utf8TcpPeer peer, string responseCode, string contentType, byte[] data, params string[] extraHeaders)
        {
            peer.Send("HTTP/1.0 {0}", responseCode);
            peer.Send("Server: moonsharp-remote-debugger/{0}", VERSION);
            peer.Send("Content-Type: {0}", contentType);
            peer.Send("Content-Length: {0}", data.Length);
            peer.Send("Connection: close");
            peer.Send("Cache-Control: max-age=0, no-cache");

            foreach (string h in extraHeaders)
            {
                peer.Send(h);
            }

            peer.Send("");
            peer.SendBinary(data);
        }
示例#5
0
 private void SendHttp(Utf8TcpPeer peer, string responseCode, string contentType, string data, params string[] extraHeaders)
 {
     SendHttp(peer, responseCode, contentType, Encoding.UTF8.GetBytes(data), extraHeaders);
 }
示例#6
0
		private void ExecHttpRequest(Utf8TcpPeer peer, List<string> httpdata)
		{
			try
			{
				if (Authenticator != null)
				{
					string authstr = httpdata.FirstOrDefault(s => s.StartsWith("Authorization:"));
					bool authorized = false;

					if (authstr != null)
					{
						string user, password;
						ParseAuthenticationString(authstr, out user, out password);
						authorized = Authenticator(user, password);
					}

					if (!authorized)
					{
						SendHttp(peer, "401 Not Authorized", "text/html", ERROR_401, "WWW-Authenticate: Basic realm=\"moonsharp-remote-debugger\"");
						return;
					}
				}

				HttpResource res = GetResourceFromPath(httpdata[0]);

				if (res == null)
				{
					SendHttp(peer, "404 Not Found", "text/html", ERROR_404);
				}
				else
				{
					SendHttp(peer, "200 OK", res.GetContentTypeString(), res.Data);
				}
			}
			catch (Exception ex)
			{
				m_Server.Logger(ex.Message);

				try
				{
					SendHttp(peer, "500 Internal Server Error", "text/html", ERROR_500);
				}
				catch (Exception ex2)
				{
					m_Server.Logger(ex2.Message);
				}
			}
		}
示例#7
0
		private void SendHttp(Utf8TcpPeer peer, string responseCode, string contentType, string data, params string[] extraHeaders)
		{
			SendHttp(peer, responseCode, contentType, Encoding.UTF8.GetBytes(data), extraHeaders);
		}
示例#8
0
		public Utf8TcpPeerEventArgs(Utf8TcpPeer peer, string message = null)
		{
			Peer = peer;
			Message = message;
		}
示例#9
0
		private void AddNewClient(Socket socket)
		{
			if ((Options & Utf8TcpServerOptions.SingleClientOnly) != 0)
			{
				lock (m_PeerListLock)
				{
					foreach (var pp in m_PeerList)
					{
						pp.Disconnect();
					}
				}
			}

			Utf8TcpPeer peer = new Utf8TcpPeer(this, socket);

			lock (m_PeerListLock)
			{
				m_PeerList.Add(peer);
				peer.ConnectionClosed += OnPeerDisconnected;
				peer.DataReceived += OnPeerDataReceived;
			}


			if (ClientConnected != null)
			{
				Utf8TcpPeerEventArgs args = new Utf8TcpPeerEventArgs(peer);
				ClientConnected(this, args);
			} 
			
			peer.Start();
		}
示例#10
0
 public Utf8TcpPeerEventArgs(Utf8TcpPeer peer, string message = null)
 {
     Peer    = peer;
     Message = message;
 }