本文整理汇总了C#中SocketResponder类的典型用法代码示例。如果您正苦于以下问题:C# SocketResponder类的具体用法?C# SocketResponder怎么用?C# SocketResponder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SocketResponder类属于命名空间,在下文中一共展示了SocketResponder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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 ();
}
}
示例2: ContentEncoding_Disposed
public void ContentEncoding_Disposed ()
{
IPEndPoint ep = NetworkHelpers.LocalEphemeralEndPoint();
string url = "http://" + ep.ToString () + "/test/";
using (SocketResponder responder = new SocketResponder (ep, s => FullResponseHandler (s))) {
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");
}
}
}
示例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) {
}
*/
}
}
示例4: FaultTest
[Test] // bug #81886
public void FaultTest ()
{
IPEndPoint localEP = new IPEndPoint (IPAddress.Loopback, 5000);
using (SocketResponder sr = new SocketResponder (localEP, s => FaultResponse_Qualified (s))) {
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 ();
}
using (SocketResponder sr = new SocketResponder (localEP, s => FaultResponse_Unqualified (s))) {
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 ();
}
}
示例5: OutParametersTest
[Test] // bug #79988
public void OutParametersTest ()
{
IPEndPoint localEP = new IPEndPoint (IPAddress.Loopback, 5000);
using (SocketResponder sr = new SocketResponder (localEP, s => OutParametersResponse (s))) {
FooService service = new FooService ();
service.Url = "http://" + IPAddress.Loopback.ToString () + ":5000/";
int a;
bool b;
Elem [] e = service.Req ("x", out a, out b);
Assert.IsNull (e, "#A1");
Assert.AreEqual (0, a, "#A2");
Assert.IsFalse (b, "#A3");
service.Dispose ();
}
}
示例6: Close_Disposed
public void Close_Disposed ()
{
IPEndPoint ep = NetworkHelpers.LocalEphemeralEndPoint();
string url = "http://" + ep.ToString () + "/test/";
using (SocketResponder responder = new SocketResponder (ep, s => FullResponseHandler (s))) {
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 ();
}
}
示例7: Run
static int Run (IPEndPoint ep)
{
string url = "http://" + ep.ToString () + "/test/";
using (SocketResponder responder = new SocketResponder (ep, new SocketRequestHandler (EchoRequestHandler))) {
HttpWebRequest req;
Stream rs;
req = (HttpWebRequest) WebRequest.Create (url);
req.Method = "POST";
req.ContentLength = 2;
rs = req.GetRequestStream ();
rs.WriteByte (0x0d);
try {
rs.Close ();
return 1;
} catch (WebException) {
}
req = (HttpWebRequest) WebRequest.Create (url);
req.Method = "POST";
req.ContentLength = 2;
rs = req.GetRequestStream ();
rs.WriteByte (0x0d);
try {
rs.Close ();
return 2;
} catch (WebException) {
}
req = (HttpWebRequest) WebRequest.Create (url);
req.Method = "POST";
req.ContentLength = 2;
rs = req.GetRequestStream ();
rs.WriteByte (0x0d);
rs.WriteByte (0x0d);
rs.Close ();
req.Abort ();
responder.Stop ();
}
return 0;
}
示例8: StatusCode_Disposed
public void StatusCode_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 ();
Assert.AreEqual (HttpStatusCode.OK, resp.StatusCode);
}
}
示例9: Read_Stream_Closed
public void Read_Stream_Closed ()
{
IPEndPoint ep = NetworkHelpers.LocalEphemeralEndPoint();
string url = "http://" + ep.ToString () + "/test/";
using (SocketResponder responder = new SocketResponder (ep, s => HttpWebResponseTest.FullResponseHandler (s))) {
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 ();
}
}
}
}
示例10: Cookies_Disposed
public void Cookies_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 {
CookieCollection cookies = resp.Cookies;
Assert.Fail ("#A1:" + cookies);
} catch (ObjectDisposedException ex) {
Assert.AreEqual (typeof (ObjectDisposedException), ex.GetType (), "#A2");
Assert.IsNull (ex.InnerException, "#A3");
Assert.IsNotNull (ex.Message, "#A4");
Assert.AreEqual (typeof (HttpWebResponse).FullName, ex.ObjectName, "#A5");
}
try {
resp.Cookies = new CookieCollection ();
Assert.Fail ("#B1");
} catch (ObjectDisposedException ex) {
Assert.AreEqual (typeof (ObjectDisposedException), ex.GetType (), "#B2");
Assert.IsNull (ex.InnerException, "#B3");
Assert.IsNotNull (ex.Message, "#B4");
Assert.AreEqual (typeof (HttpWebResponse).FullName, ex.ObjectName, "#B5");
}
}
}
示例11: 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, s => EchoRequestHandler (s))) {
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);
}
}
示例12: Read
public void Read ()
{
IPEndPoint ep = NetworkHelpers.LocalEphemeralEndPoint();
string url = "http://" + ep.ToString () + "/test/";
using (SocketResponder responder = new SocketResponder (ep, s => HttpWebResponseTest.FullResponseHandler (s))) {
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 ();
}
}
}
}
示例13: CanWrite
public void CanWrite ()
{
IPEndPoint ep = NetworkHelpers.LocalEphemeralEndPoint();
string url = "http://" + ep.ToString () + "/test/";
using (SocketResponder responder = new SocketResponder (ep, s => HttpWebResponseTest.FullResponseHandler (s))) {
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 ();
}
}
}
}
示例14: BeginWrite
public void BeginWrite ()
{
IPEndPoint ep = NetworkHelpers.LocalEphemeralEndPoint();
string url = "http://" + ep.ToString () + "/test/";
using (SocketResponder responder = new SocketResponder (ep, s => HttpWebResponseTest.FullResponseHandler (s))) {
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 ();
}
}
}
}
示例15: Headers_Disposed
public void Headers_Disposed ()
{
IPEndPoint ep = NetworkHelpers.LocalEphemeralEndPoint();
string url = "http://" + ep.ToString () + "/test/";
using (SocketResponder responder = new SocketResponder (ep, s => FullResponseHandler (s))) {
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");
}
}