SimpleClientTransportSink.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. //
  2. // System.Runtime.Remoting.Channels.Simple.SimpleClientTransportSink.cs
  3. //
  4. // Author: Dietmar Maurer ([email protected])
  5. //
  6. // 2002 (C) Copyright, Ximian, Inc.
  7. //
  8. //
  9. // Permission is hereby granted, free of charge, to any person obtaining
  10. // a copy of this software and associated documentation files (the
  11. // "Software"), to deal in the Software without restriction, including
  12. // without limitation the rights to use, copy, modify, merge, publish,
  13. // distribute, sublicense, and/or sell copies of the Software, and to
  14. // permit persons to whom the Software is furnished to do so, subject to
  15. // the following conditions:
  16. //
  17. // The above copyright notice and this permission notice shall be
  18. // included in all copies or substantial portions of the Software.
  19. //
  20. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  21. // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  22. // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  23. // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
  24. // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
  25. // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
  26. // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  27. //
  28. using System.Collections;
  29. using System.IO;
  30. using System.Net.Sockets;
  31. using System.Runtime.Remoting.Messaging;
  32. using System.Runtime.Remoting.Channels;
  33. namespace System.Runtime.Remoting.Channels.Simple
  34. {
  35. internal class SimpleClientTransportSink : IClientChannelSink
  36. {
  37. string host;
  38. string object_uri;
  39. int port;
  40. TcpClient tcpclient;
  41. Stream network_stream;
  42. public SimpleClientTransportSink (string url)
  43. {
  44. host = SimpleChannel.ParseSimpleURL (url, out object_uri, out port);
  45. tcpclient = new TcpClient ();
  46. }
  47. public IDictionary Properties
  48. {
  49. get {
  50. return null;
  51. }
  52. }
  53. public IClientChannelSink NextChannelSink
  54. {
  55. get {
  56. // we are the last one
  57. return null;
  58. }
  59. }
  60. public void AsyncProcessRequest (IClientChannelSinkStack sinkStack, IMessage msg,
  61. ITransportHeaders headers, Stream stream)
  62. {
  63. throw new NotImplementedException ();
  64. }
  65. public void AsyncProcessResponse (IClientResponseChannelSinkStack sinkStack,
  66. object state, ITransportHeaders headers,
  67. Stream stream)
  68. {
  69. throw new NotImplementedException ();
  70. }
  71. public Stream GetRequestStream (IMessage msg, ITransportHeaders headers)
  72. {
  73. // no direct access to the stream
  74. return null;
  75. }
  76. public void ProcessMessage (IMessage msg,
  77. ITransportHeaders requestHeaders,
  78. Stream requestStream,
  79. out ITransportHeaders responseHeaders,
  80. out Stream responseStream)
  81. {
  82. // get a network stream
  83. if (network_stream == null) {
  84. tcpclient.Connect (host, port);
  85. network_stream = tcpclient.GetStream ();
  86. }
  87. // send the message
  88. SimpleMessageFormat.SendMessageStream (network_stream, (MemoryStream)requestStream,
  89. SimpleMessageFormat.MessageType.Request,
  90. object_uri);
  91. // read the response fro the network an copy it to a memory stream
  92. SimpleMessageFormat.MessageType msg_type;
  93. string uri;
  94. MemoryStream mem_stream = SimpleMessageFormat.ReceiveMessageStream (network_stream, out msg_type, out uri);
  95. // close the stream
  96. //tcpclient.Close ();
  97. switch (msg_type) {
  98. case SimpleMessageFormat.MessageType.Response:
  99. //fixme: read response message
  100. responseHeaders = null;
  101. responseStream = mem_stream;
  102. break;
  103. default:
  104. throw new Exception ("unknown response mesage header");
  105. }
  106. }
  107. }
  108. }