当前位置: 首页>>代码示例>>C#>>正文


C# SocketResponder.Start方法代码示例

本文整理汇总了C#中SocketResponder.Start方法的典型用法代码示例。如果您正苦于以下问题:C# SocketResponder.Start方法的具体用法?C# SocketResponder.Start怎么用?C# SocketResponder.Start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在SocketResponder的用法示例。


在下文中一共展示了SocketResponder.Start方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Main

	static void Main ()
	{
		IPEndPoint localEP = new IPEndPoint (IPAddress.Loopback, 5000);
		using (SocketResponder sr = new SocketResponder (localEP, new SocketRequestHandler (Response_Bug80944))) {
			sr.Start ();

			HttpWebRequest req = (HttpWebRequest) WebRequest.Create (
				"http://" + sr.LocalEndPoint.Address.ToString () + ":5000/");
			req.KeepAlive = false;
			req.Method = "GET";
			req.ReadWriteTimeout = 2000;
#if NET_2_0
			req.Proxy = null;
#endif
			req.Timeout = 2000;
#if NET_2_0
			Assert.IsNull (req.Proxy, "#1");
#else
			Assert.IsNotNull (req.Proxy, "#1");
#endif

			HttpWebResponse resp = (HttpWebResponse) req.GetResponse ();
			using (StreamReader r = new StreamReader (resp.GetResponseStream (), Encoding.UTF8)) {
				Assert.AreEqual ("FINE", r.ReadToEnd (), "#2");
			}
			resp.Close ();
		}
	}
开发者ID:mono,项目名称:gert,代码行数:28,代码来源:test.cs

示例2: ContentEncoding_Disposed

		public void ContentEncoding_Disposed ()
		{
			IPEndPoint ep = NetworkHelpers.LocalEphemeralEndPoint();
			string url = "http://" + ep.ToString () + "/test/";

			using (SocketResponder responder = new SocketResponder (ep, new SocketRequestHandler (FullResponseHandler))) {
				responder.Start ();

				HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url);
				req.Method = "GET";
				req.Timeout = 2000;
				req.ReadWriteTimeout = 2000;
				req.KeepAlive = false;

				HttpWebResponse resp = (HttpWebResponse) req.GetResponse ();
				((IDisposable) resp).Dispose ();

				try {
					string enc = resp.ContentEncoding;
					Assert.Fail ("#1:" + enc);
				} catch (ObjectDisposedException ex) {
					Assert.AreEqual (typeof (ObjectDisposedException), ex.GetType (), "#2");
					Assert.IsNull (ex.InnerException, "#3");
					Assert.IsNotNull (ex.Message, "#4");
					Assert.AreEqual (typeof (HttpWebResponse).FullName, ex.ObjectName, "#5");
				}
			}
		}
开发者ID:Profit0004,项目名称:mono,代码行数:28,代码来源:HttpWebResponseTest.cs

示例3: CloseTest

		[Test] // bug #81105
		public void CloseTest ()
		{
			IPEndPoint localEP = new IPEndPoint (IPAddress.Loopback, 8765);
			using (SocketResponder sr = new SocketResponder (localEP, new SocketRequestHandler (CloseRequestHandler))) {
				sr.Start ();

				TcpClient tcpClient = new TcpClient (IPAddress.Loopback.ToString (), 8765);
				NetworkStream ns = tcpClient.GetStream ();
				Assert.IsNotNull (ns, "#A1");
				Assert.AreEqual (0, tcpClient.Available, "#A2");
				Assert.IsTrue (tcpClient.Connected, "#A3");
				// Assert.IsFalse (tcpClient.ExclusiveAddressUse, "#A4");
				tcpClient.Close ();
				Assert.IsNotNull (tcpClient.Client, "#A5");
				try {
					int available = tcpClient.Available;
					Assert.Fail ("#A6: " + available);
				} catch (ObjectDisposedException) {
				}
				Assert.IsFalse (tcpClient.Connected, "#A7");
				// not supported on linux
				/*
				try {
					bool exclusive = tcpClient.ExclusiveAddressUse;
					Assert.Fail ("#A8: " + exclusive);
				} catch (ObjectDisposedException) {
				}
				*/
			}

			using (SocketResponder sr = new SocketResponder (localEP, new SocketRequestHandler (CloseRequestHandler))) {
				sr.Start ();

				TcpClient tcpClient = new TcpClient (IPAddress.Loopback.ToString (), 8765);
				Assert.AreEqual (0, tcpClient.Available, "#B1");
				Assert.IsTrue (tcpClient.Connected, "#B2");
				// Assert.IsFalse (tcpClient.ExclusiveAddressUse, "#B3");
				tcpClient.Close ();
				Assert.IsNull (tcpClient.Client, "#B4");
				try {
					int available = tcpClient.Available;
					Assert.Fail ("#B5: " + available);
				} catch (NullReferenceException) {
				}
				try {
					bool connected = tcpClient.Connected;
					Assert.Fail ("#B6: " + connected);
				} catch (NullReferenceException) {
				}
				// not supported on linux
				/*
				try {
					bool exclusive = tcpClient.ExclusiveAddressUse;
					Assert.Fail ("#B7: " + exclusive);
				} catch (NullReferenceException) {
				}
				*/
			}
		}
开发者ID:Profit0004,项目名称:mono,代码行数:60,代码来源:TcpClientTest.cs

示例4: Close_Disposed

		public void Close_Disposed ()
		{
			IPEndPoint ep = NetworkHelpers.LocalEphemeralEndPoint();
			string url = "http://" + ep.ToString () + "/test/";

			using (SocketResponder responder = new SocketResponder (ep, new SocketRequestHandler (FullResponseHandler))) {
				responder.Start ();

				HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url);
				req.Method = "GET";
				req.Timeout = 2000;
				req.ReadWriteTimeout = 2000;
				req.KeepAlive = false;

				HttpWebResponse resp = (HttpWebResponse) req.GetResponse ();
				((IDisposable) resp).Dispose ();
				resp.Close ();
			}
		}
开发者ID:Profit0004,项目名称:mono,代码行数:19,代码来源:HttpWebResponseTest.cs

示例5: UploadAsyncCancelEventTest

		public void UploadAsyncCancelEventTest (int port, Action<WebClient, Uri, EventWaitHandle> uploadAction)
		{
			var ep = NetworkHelpers.LocalEphemeralEndPoint ();
			string url = "http://" + ep.ToString() + "/test/";

			using (var responder = new SocketResponder (ep, EchoRequestHandler))
			{
				responder.Start ();

				var webClient = new WebClient ();

				var cancellationTokenSource = new CancellationTokenSource ();
				cancellationTokenSource.Token.Register (webClient.CancelAsync);

				var cancelEvent = new ManualResetEvent (false);

				uploadAction.Invoke (webClient, new Uri (url), cancelEvent);

				cancellationTokenSource.Cancel ();

				Assert.IsTrue (cancelEvent.WaitOne (1000));
			}
		}
开发者ID:Profit0004,项目名称:mono,代码行数:23,代码来源:WebClientTest.cs

示例6: UploadValues1

		[Category ("AndroidNotWorking")] // Fails when ran as part of the entire BCL test suite. Works when only this fixture is ran
		public void UploadValues1 ()
		{
			IPEndPoint ep = NetworkHelpers.LocalEphemeralEndPoint ();
			string url = "http://" + ep.ToString () + "/test/";

			using (SocketResponder responder = new SocketResponder (ep, new SocketRequestHandler (EchoRequestHandler))) {
				responder.Start ();

				WebClient wc = new WebClient ();
				wc.Encoding = Encoding.ASCII;

				NameValueCollection nvc = new NameValueCollection ();
				nvc.Add ("Name", "\u0041\u2262\u0391\u002E");
				nvc.Add ("Address", "\u002E\u2262\u0041\u0391");

				byte [] buffer = wc.UploadValues (url, nvc);
				string response = Encoding.UTF8.GetString (buffer);
				Assert.AreEqual ("Name=A%e2%89%a2%ce%91.&Address=.%e2%89%a2A%ce%91\r\n", response);
			}
		}
开发者ID:Profit0004,项目名称:mono,代码行数:21,代码来源:WebClientTest.cs

示例7: FaultTest

		[Test] // bug #81886
		public void FaultTest ()
		{
			IPEndPoint localEP = new IPEndPoint (IPAddress.Loopback, 5000);
			using (SocketResponder sr = new SocketResponder (localEP, new SocketRequestHandler (FaultResponse_Qualified))) {
				sr.Start ();

				FooService service = new FooService ();
				service.Url = "http://" + IPAddress.Loopback.ToString () + ":5000/";
				try {
					service.Run ();
					Assert.Fail ("#A1");
				} catch (SoapException ex) {
					Assert.AreEqual ("Mono Web Service", ex.Actor, "#A2");
					Assert.AreEqual (SoapException.ServerFaultCode, ex.Code, "#A3");
					Assert.IsNotNull (ex.Detail, "#A4");
					Assert.AreEqual ("detail", ex.Detail.LocalName, "#A5");
					Assert.AreEqual ("http://schemas.xmlsoap.org/soap/envelope/", ex.Detail.NamespaceURI, "#A6");

					XmlNamespaceManager nsMgr = new XmlNamespaceManager (ex.Detail.OwnerDocument.NameTable);
					nsMgr.AddNamespace ("se", "http://www.mono-project/System");

					XmlElement systemError = (XmlElement) ex.Detail.SelectSingleNode (
						"se:systemerror", nsMgr);
					Assert.IsNotNull (systemError, "#A7");
					Assert.IsNull (ex.InnerException, "#A8");
					Assert.AreEqual ("Failure processing request.", ex.Message, "#A9");
				}
				service.Dispose ();

				sr.Stop ();
			}

			using (SocketResponder sr = new SocketResponder (localEP, new SocketRequestHandler (FaultResponse_Unqualified))) {
				sr.Start ();

				FooService service = new FooService ();
				service.Url = "http://" + IPAddress.Loopback.ToString () + ":5000/";
				try {
					service.Run ();
					Assert.Fail ("#B1");
				} catch (SoapException ex) {
					Assert.AreEqual ("Mono Web Service", ex.Actor, "#B2");
					Assert.AreEqual (SoapException.ServerFaultCode, ex.Code, "#B3");
					Assert.IsNotNull (ex.Detail, "#B4");
					Assert.AreEqual ("detail", ex.Detail.LocalName, "#B5");
					Assert.AreEqual (string.Empty, ex.Detail.NamespaceURI, "#B6");

					XmlNamespaceManager nsMgr = new XmlNamespaceManager (ex.Detail.OwnerDocument.NameTable);
					nsMgr.AddNamespace ("se", "http://www.mono-project/System");

					XmlElement systemError = (XmlElement) ex.Detail.SelectSingleNode (
						"se:systemerror", nsMgr);
					Assert.IsNotNull (systemError, "#B7");
					Assert.IsNull (ex.InnerException, "#B8");
					Assert.AreEqual ("Failure processing request.", ex.Message, "#B9");
				}
				service.Dispose ();

				sr.Stop ();
			}
		}
开发者ID:mweilb,项目名称:mono,代码行数:62,代码来源:SoapHttpClientProtocolTest.cs

示例8: Read_Offset_Overflow

		public void Read_Offset_Overflow ()
		{
			IPEndPoint ep = NetworkHelpers.LocalEphemeralEndPoint();
			string url = "http://" + ep.ToString () + "/test/";

			using (SocketResponder responder = new SocketResponder (ep, new SocketRequestHandler (HttpWebResponseTest.FullResponseHandler))) {
				responder.Start ();

				HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url);
				req.Method = "GET";
				req.Timeout = 2000;
				req.ReadWriteTimeout = 2000;
				req.KeepAlive = false;

				using (HttpWebResponse resp = (HttpWebResponse) req.GetResponse ()) {
					Stream rs = resp.GetResponseStream ();
					byte [] buffer = new byte [5];
					try {
						try {
							rs.Read (buffer, buffer.Length + 1, 0);
							Assert.Fail ("#A1");
						} catch (ArgumentOutOfRangeException ex) {
							// Specified argument was out of the range of valid values
							Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#A2");
							Assert.IsNull (ex.InnerException, "#A3");
							Assert.IsNotNull (ex.Message, "#A4");
							Assert.AreEqual ("offset", ex.ParamName, "#A5");
						}

						// read full response
						buffer = new byte [24];
						Assert.AreEqual (9, rs.Read (buffer, 0, buffer.Length));

						try {
							rs.Read (buffer, buffer.Length + 1, 0);
							Assert.Fail ("#B1");
						} catch (ArgumentOutOfRangeException ex) {
							// Specified argument was out of the range of valid values
							Assert.AreEqual (typeof (ArgumentOutOfRangeException), ex.GetType (), "#B2");
							Assert.IsNull (ex.InnerException, "#B3");
							Assert.IsNotNull (ex.Message, "#B4");
							Assert.AreEqual ("offset", ex.ParamName, "#B5");
						}
					} finally {
						rs.Close ();
						req.Abort ();
					}
				}
			}
		}
开发者ID:Profit0004,项目名称:mono,代码行数:50,代码来源:HttpWebResponseTest.cs

示例9: Read

		public void Read ()
		{
			IPEndPoint ep = NetworkHelpers.LocalEphemeralEndPoint();
			string url = "http://" + ep.ToString () + "/test/";

			using (SocketResponder responder = new SocketResponder (ep, new SocketRequestHandler (HttpWebResponseTest.FullResponseHandler))) {
				responder.Start ();

				HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url);
				req.Method = "GET";
				req.Timeout = 2000;
				req.ReadWriteTimeout = 2000;
				req.KeepAlive = false;

				using (HttpWebResponse resp = (HttpWebResponse) req.GetResponse ()) {
					Stream rs = resp.GetResponseStream ();
					byte [] buffer = new byte [5];
					try {
						Assert.AreEqual (1, rs.Read (buffer, 4, 1), "#A1");
						Assert.AreEqual (new byte [] { 0x00, 0x00, 0x00, 0x00, 0x3c }, buffer, "#A2");
						Assert.AreEqual (2, rs.Read (buffer, 0, 2), "#B1");
						Assert.AreEqual (new byte [] { 0x64, 0x75, 0x00, 0x00, 0x3c }, buffer, "#B2");
						Assert.AreEqual (4, rs.Read (buffer, 1, 4), "#C1");
						Assert.AreEqual (new byte [] { 0x64, 0x6d, 0x6d, 0x79, 0x20 }, buffer, "#C2");
						Assert.AreEqual (2, rs.Read (buffer, 0, 3), "#D1");
						Assert.AreEqual (new byte [] { 0x2f, 0x3e, 0x6d, 0x79, 0x20 }, buffer, "#D2");
						Assert.AreEqual (0, rs.Read (buffer, 1, 3), "#E1");
						Assert.AreEqual (new byte [] { 0x2f, 0x3e, 0x6d, 0x79, 0x20 }, buffer, "#E2");
						Assert.AreEqual (0, rs.Read (buffer, buffer.Length, 0), "#G1");
						Assert.AreEqual (new byte [] { 0x2f, 0x3e, 0x6d, 0x79, 0x20 }, buffer, "#G2");
					} finally {
						rs.Close ();
						req.Abort ();
					}
				}
			}
		}
开发者ID:Profit0004,项目名称:mono,代码行数:37,代码来源:HttpWebResponseTest.cs

示例10: CanWrite

		public void CanWrite ()
		{
			IPEndPoint ep = NetworkHelpers.LocalEphemeralEndPoint();
			string url = "http://" + ep.ToString () + "/test/";

			using (SocketResponder responder = new SocketResponder (ep, new SocketRequestHandler (HttpWebResponseTest.FullResponseHandler))) {
				responder.Start ();

				HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url);
				req.Method = "GET";
				req.Timeout = 2000;
				req.ReadWriteTimeout = 2000;
				req.KeepAlive = false;

				using (HttpWebResponse resp = (HttpWebResponse) req.GetResponse ()) {
					Stream rs = resp.GetResponseStream ();
					try {
						Assert.IsFalse (rs.CanWrite, "#1");
						rs.Close ();
						Assert.IsFalse (rs.CanWrite, "#2");
					} finally {
						rs.Close ();
						req.Abort ();
					}
				}
			}
		}
开发者ID:Profit0004,项目名称:mono,代码行数:27,代码来源:HttpWebResponseTest.cs

示例11: BeginWrite

		public void BeginWrite ()
		{
			IPEndPoint ep = NetworkHelpers.LocalEphemeralEndPoint();
			string url = "http://" + ep.ToString () + "/test/";

			using (SocketResponder responder = new SocketResponder (ep, new SocketRequestHandler (HttpWebResponseTest.FullResponseHandler))) {
				responder.Start ();

				HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url);
				req.Method = "GET";
				req.Timeout = 2000;
				req.ReadWriteTimeout = 2000;
				req.KeepAlive = false;

				using (HttpWebResponse resp = (HttpWebResponse) req.GetResponse ()) {
					Stream rs = resp.GetResponseStream ();
					byte [] buffer = new byte [5];
					try {
						rs.BeginWrite (buffer, 0, buffer.Length, null, null);
						Assert.Fail ("#1");
					} catch (NotSupportedException ex) {
						// The stream does not support writing
						Assert.AreEqual (typeof (NotSupportedException), ex.GetType (), "#2");
						Assert.IsNull (ex.InnerException, "#3");
						Assert.IsNotNull (ex.Message, "#4");
					} finally {
						rs.Close ();
						req.Abort ();
					}
				}
			}
		}
开发者ID:Profit0004,项目名称:mono,代码行数:32,代码来源:HttpWebResponseTest.cs

示例12: Headers_Disposed

		public void Headers_Disposed ()
		{
			IPEndPoint ep = NetworkHelpers.LocalEphemeralEndPoint();
			string url = "http://" + ep.ToString () + "/test/";

			using (SocketResponder responder = new SocketResponder (ep, new SocketRequestHandler (FullResponseHandler))) {
				responder.Start ();

				HttpWebRequest req = (HttpWebRequest) WebRequest.Create (url);
				req.Method = "GET";
				req.Timeout = 2000;
				req.ReadWriteTimeout = 2000;
				req.KeepAlive = false;

				HttpWebResponse resp = (HttpWebResponse) req.GetResponse ();
				((IDisposable) resp).Dispose ();

				WebHeaderCollection headers = resp.Headers;
				Assert.AreEqual (6, headers.Count, "#1");
				Assert.AreEqual ("9", headers ["Content-Length"], "#2");
				Assert.AreEqual ("utf-8", headers ["Content-Encoding"], "#3");
				Assert.AreEqual ("text/xml; charset=UTF-8", headers ["Content-Type"], "#4");
				Assert.AreEqual ("Wed, 08 Jan 2003 23:11:55 GMT", headers ["Last-Modified"], "#5");
				Assert.AreEqual ("UserID=Miguel,StoreProfile=true", headers ["Set-Cookie"], "#6");
				Assert.AreEqual ("Mono/Test", headers ["Server"], "#7");
			}
		}
开发者ID:Profit0004,项目名称:mono,代码行数:27,代码来源:HttpWebResponseTest.cs

示例13: Read_Stream_Closed

		public void Read_Stream_Closed ()
		{
			IPEndPoint ep = NetworkHelpers.LocalEphemeralEndPoint();
			string url = "http://" + ep.ToString () + "/test/";

			using (SocketResponder responder = new SocketResponder (ep, new SocketRequestHandler (HttpWebResponseTest.FullResponseHandler))) {
				responder.Start ();

				HttpWebRequest req;
				
				req = (HttpWebRequest) WebRequest.Create (url);
				req.Method = "GET";
				req.Timeout = 2000;
				req.ReadWriteTimeout = 2000;
				req.KeepAlive = false;

				using (HttpWebResponse resp = (HttpWebResponse) req.GetResponse ()) {
					Stream rs = resp.GetResponseStream ();
					rs.Close ();
					try {
						rs.Read (new byte [0], 0, 0);
						Assert.Fail ("#A1");
					} catch (WebException ex) {
						// The request was aborted: The connection was closed unexpectedly
						Assert.AreEqual (typeof (WebException), ex.GetType (), "#A2");
						Assert.IsNull (ex.InnerException, "#A3");
						Assert.IsNotNull (ex.Message, "#A4");
						Assert.IsNull (ex.Response, "#A5");
						Assert.AreEqual (WebExceptionStatus.ConnectionClosed, ex.Status, "#A6");
					} finally {
						rs.Close ();
						req.Abort ();
					}
				}

				req = (HttpWebRequest) WebRequest.Create (url);
				req.Method = "GET";
				req.Timeout = 2000;
				req.ReadWriteTimeout = 2000;
				req.KeepAlive = false;

				using (HttpWebResponse resp = (HttpWebResponse) req.GetResponse ()) {
					Stream rs = resp.GetResponseStream ();
					byte [] buffer = new byte [24];
					Assert.AreEqual (9, rs.Read (buffer, 0, buffer.Length));
					rs.Close ();
					try {
						rs.Read (new byte [0], 0, 0);
						Assert.Fail ("#B1");
					} catch (WebException ex) {
						// The request was aborted: The connection was closed unexpectedly
						Assert.AreEqual (typeof (WebException), ex.GetType (), "#B2");
						Assert.IsNull (ex.InnerException, "#B3");
						Assert.IsNotNull (ex.Message, "#B4");
						Assert.IsNull (ex.Response, "#B5");
						Assert.AreEqual (WebExceptionStatus.ConnectionClosed, ex.Status, "#B6");
					} finally {
						rs.Close ();
						req.Abort ();
					}
				}
			}
		}
开发者ID:Profit0004,项目名称:mono,代码行数:63,代码来源:HttpWebResponseTest.cs


注:本文中的SocketResponder.Start方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。