Esempio n. 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();
        }
Esempio n. 2
0
        void OnDataReceivedAny(object sender, Utf8TcpPeerEventArgs e)
        {
            lock (m_Lock)
            {
                List <string> httpdata;

                string msg = e.Message.Replace("\n", "").Replace("\r", "");

                if (!m_HttpData.TryGetValue(e.Peer.Id, out httpdata))
                {
                    httpdata = new List <string>();
                    m_HttpData.Add(e.Peer.Id, httpdata);
                }

                if (msg.Length == 0)
                {
                    ExecHttpRequest(e.Peer, httpdata);
                    e.Peer.Disconnect();
                }
                else
                {
                    httpdata.Add(msg);
                }
            }
        }
Esempio n. 3
0
		void OnDataReceivedAny(object sender, Utf8TcpPeerEventArgs e)
		{
			lock (m_Lock)
			{
				List<string> httpdata;

				string msg = e.Message.Replace("\n", "").Replace("\r", "");

				if (!m_HttpData.TryGetValue(e.Peer.Id, out httpdata))
				{
					httpdata = new List<string>();
					m_HttpData.Add(e.Peer.Id, httpdata);
				}

				if (msg.Length == 0)
				{
					ExecHttpRequest(e.Peer, httpdata);
					e.Peer.Disconnect();
				}
				else
				{
					httpdata.Add(msg);
				}
			}
		}
Esempio n. 4
0
 private void OnPeerDataReceived(object sender, Utf8TcpPeerEventArgs e)
 {
     if (DataReceived != null)
     {
         DataReceived(this, e);
     }
 }
Esempio n. 5
0
 void OnClientDisconnected(object sender, Utf8TcpPeerEventArgs e)
 {
     lock (m_Lock)
     {
         if (m_HttpData.ContainsKey(e.Peer.Id))
         {
             m_HttpData.Remove(e.Peer.Id);
         }
     }
 }
Esempio n. 6
0
        void OnPeerDisconnected(object sender, Utf8TcpPeerEventArgs e)
        {
            try
            {
                if (ClientDisconnected != null)
                {
                    ClientDisconnected(this, e);
                }

                lock (m_PeerListLock)
                {
                    m_PeerList.Remove(e.Peer);
                    e.Peer.ConnectionClosed -= OnPeerDisconnected;
                    e.Peer.DataReceived     -= OnPeerDataReceived;
                }
            }
            catch
            {
            }
        }
Esempio n. 7
0
		static void m_Server_DataReceivedAny(object sender, Utf8TcpPeerEventArgs e)
		{
			Console.WriteLine("RCVD: {0}", e.Message);
			e.Peer.Send(e.Message.ToUpper());
		}
Esempio n. 8
0
		void OnClientDisconnected(object sender, Utf8TcpPeerEventArgs e)
		{
			lock (m_Lock)
			{
				if (m_HttpData.ContainsKey(e.Peer.Id))
					m_HttpData.Remove(e.Peer.Id);
			}
		}
Esempio n. 9
0
		void m_Server_DataReceived(object sender, Utf8TcpPeerEventArgs e)
		{
			XmlDocument xdoc = new XmlDocument();
			xdoc.LoadXml(e.Message);

			if (xdoc.DocumentElement.Name == "policy-file-request")
			{
				Send(xw =>
				{
					using (xw.Element("cross-domain-policy"))
					{
						using (xw.Element("allow-access-from"))
						{
							xw.Attribute("domain", "*");
							xw.Attribute("to-ports", m_Server.PortNumber);
						}
					}
				});
				return;
			}

			if (xdoc.DocumentElement.Name == "Command")
			{
				string cmd = xdoc.DocumentElement.GetAttribute("cmd").ToLowerInvariant();
				string arg = xdoc.DocumentElement.GetAttribute("arg");

				switch (cmd)
				{
					case "handshake":
						SendWelcome();

						for (int i = 0; i < m_Script.SourceCodeCount; i++)
							SetSourceCode(m_Script.GetSourceCode(i));
						break;
					case "stepin":
						QueueAction(new DebuggerAction() { Action = DebuggerAction.ActionType.StepIn });
						break;
					case "refresh":
						lock (m_Lock)
						{
							for (int i = 0; i < (int)WatchType.MaxValue; i++)
								m_CachedWatches[i] = null;
						}
						QueueRefresh();
						break;
					case "run":
						QueueAction(new DebuggerAction() { Action = DebuggerAction.ActionType.Run });
						break;
					case "stepover":
						QueueAction(new DebuggerAction() { Action = DebuggerAction.ActionType.StepOver });
						break;
					case "stepout":
						QueueAction(new DebuggerAction() { Action = DebuggerAction.ActionType.StepOut });
						break;
					case "pause":
						m_RequestPause = true;
						break;
					case "error_rx":
						m_ErrorRegEx = new Regex(arg.Trim());
						SendOption("error_rx", m_ErrorRegEx.ToString());
						break;
					case "addwatch":
						lock (m_Lock)
							m_WatchesChanging.UnionWith(arg.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries).Select(s => s.Trim()));

						QueueRefresh();
						break;
					case "delwatch":
						lock (m_Lock)
						{
							var args = arg.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

							foreach (var a in args)
								m_WatchesChanging.Remove(a);
						}
						QueueRefresh();
						break;
					case "breakpoint":
						DebuggerAction.ActionType action = DebuggerAction.ActionType.ToggleBreakpoint;

						if (arg == "set") action = DebuggerAction.ActionType.SetBreakpoint;
						else if (arg == "clear") action = DebuggerAction.ActionType.ClearBreakpoint;

						QueueAction(new DebuggerAction()
						{
							Action = action,
							SourceID = int.Parse(xdoc.DocumentElement.GetAttribute("src")),
							SourceLine = int.Parse(xdoc.DocumentElement.GetAttribute("line")),
							SourceCol = int.Parse(xdoc.DocumentElement.GetAttribute("col")),
						});
						break;
				}

			}
		}
Esempio n. 10
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();
		}
Esempio n. 11
0
		void OnPeerDisconnected(object sender, Utf8TcpPeerEventArgs e)
        {
            try
            {
				if (ClientDisconnected != null)
				{
					ClientDisconnected(this, e);
				}

                lock (m_PeerListLock)
                {
                    m_PeerList.Remove(e.Peer);
					e.Peer.ConnectionClosed -= OnPeerDisconnected;
					e.Peer.DataReceived -= OnPeerDataReceived;
				}
            }
            catch
            {
            }
        }
Esempio n. 12
0
		private void OnPeerDataReceived(object sender, Utf8TcpPeerEventArgs e)
		{
			if (DataReceived != null)
			{
				DataReceived(this, e);
			}
		}