17 using System.Collections.Generic;
23 namespace Deveel.Data.Protocol {
25 public const int DefaultPort = 6669;
32 object hostObj, portObj;
33 if (!properties.TryGetValue(
"Host", out hostObj))
34 throw new InvalidOperationException(
"Could not find the host address.");
36 var host = (string) hostObj;
37 var port = DefaultPort;
39 if (properties.TryGetValue(
"Port", out portObj))
42 var address =
new StringBuilder(host);
43 if (port > 0 && port != DefaultPort)
44 address.AppendFormat(
":{0}", port);
51 int port = DefaultPort;
53 var sepIndex = address.IndexOf(
':');
55 string sPort = address.Substring(sepIndex + 1);
56 if (!Int32.TryParse(sPort, out port))
57 throw new FormatException();
59 address = address.Substring(0, sepIndex);
62 return new IPEndPoint(IPAddress.Parse(address), port);
66 if (remoteEndPoint == null)
67 throw new ArgumentNullException(
"remoteEndPoint");
69 throw new ArgumentException();
71 var endPoint = ParseEndPoint(remoteEndPoint.
Address);
73 var sockect =
new Socket(endPoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
74 sockect.SendTimeout = Timeout;
75 sockect.ReceiveTimeout = Timeout;
76 sockect.Connect(endPoint);
78 return new NetworkStream(sockect, access,
true);
override NetworkStream CreateNetworkStream(ConnectionEndPoint remoteEndPoint, FileAccess access)
override ConnectionEndPoint MakeEndPoint(IDictionary< string, object > properties)
EndPoint ParseEndPoint(string s)