这只是许多可能的实现之一,还应该概述如何创建“翻译器”以及随后的“翻译连接”。显然(或不这样)可以在基类中以及在接口中概述 Send 和 Receive 方法,以便在需要时允许跨网络通信。
“连接”类为任何类型的连接定义了一个合适的基础。'NetworkConnection' 增加了对网络的要求,最后是一个 'IPNetworkConnection' 来实现 IP 协议所需的逻辑。这也可以扩展到“TcpNetworkConnection”,然后扩展到“TcpIpNetworkConnection”或以任何其他所需的方式,例如“SerialConnection”或“EthernetConnection”,然后构建一个类以允许跨媒体通信,例如“SerialToEthernetNetworkConnection”等。
例如:
#region Copyright
/*
This file came from Managed Media Aggregation, You can always find the latest version @ https://net7mma.codeplex.com/
Julius.Friedman@gmail.com / (SR. Software Engineer ASTI Transportation Inc. http://www.asti-trans.com)
Permission is hereby granted, free of charge,
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction,
* including without limitation the rights to :
* use,
* copy,
* modify,
* merge,
* publish,
* distribute,
* sublicense,
* and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
*
* JuliusFriedman@gmail.com should be contacted for further details.
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
*
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE,
* ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* v//
*/
#endregion
namespace Media.Sockets
{
#region TcpNetworkConnection
public class TcpNetworkConnection : NetworkConnection
{
#region Statics
public static System.Net.NetworkInformation.TcpConnectionInformation[] TcpConnectionInformation
{
get { return IPNetworkConnection.IPGlobalProperties.GetActiveTcpConnections(); }
}
#endregion
public TcpNetworkConnection(string name, bool shouldDispose) : base(name, shouldDispose) { }
}
#endregion
}
#region Copyright
/*
This file came from Managed Media Aggregation, You can always find the latest version @ https://net7mma.codeplex.com/
Julius.Friedman@gmail.com / (SR. Software Engineer ASTI Transportation Inc. http://www.asti-trans.com)
Permission is hereby granted, free of charge,
* to any person obtaining a copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction,
* including without limitation the rights to :
* use,
* copy,
* modify,
* merge,
* publish,
* distribute,
* sublicense,
* and/or sell copies of the Software,
* and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
*
*
* JuliusFriedman@gmail.com should be contacted for further details.
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
*
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE,
* ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
* v//
*/
#endregion
namespace Media.Sockets
{
#region TcpNetworkConnection
public class TcpIPNetworkConnection : IPNetworkConnection
{
#region Statics
public static System.Net.NetworkInformation.TcpConnectionInformation[] TcpConnectionInformation
{
get { return IPNetworkConnection.IPGlobalProperties.GetActiveTcpConnections(); }
}
#endregion
public TcpIPNetworkConnection() : base(string.Empty) { }
}
#endregion
}
都是有效的实现,但用于不同的目的。