コード例 #1
0
ファイル: NetServerDocument.cs プロジェクト: michyer/canape
        /// <summary>
        /// Create the base service
        /// </summary>
        /// <param name="logger">The logger to use</param>
        /// <returns>The new network service</returns>
        public override ProxyNetworkService Create(Logger logger)
        {
            ProxyNetworkService ret = null;

            if (logger == null)
            {
                logger = Logger.GetSystemLogger();
            }

            if ((_port < 0) || (_port > 65535))
            {
                throw new NetServiceException(Properties.Resources.NetServerDocument_ValidPort);
            }
            else if (_factory == null)
            {
                throw new NetServiceException(Properties.Resources.NetServerDocument_MustSpecifyServer);
            }
            else
            {
                try
                {
                    ProxyServer server = new PassThroughProxyServer(logger, _layers);

                    ProxyClient client = new NetServerProxyClient(_factory);

                    INetworkListener listener = null;

                    if (!_udp)
                    {
                        if (NetUtils.OSSupportsIPv4)
                        {
                            listener = new TcpNetworkListener(_anyBind, false, _port, logger, false);
                        }

                        if (_ipv6Bind && NetUtils.OSSupportsIPv6)
                        {
                            INetworkListener ipv6Listener = new TcpNetworkListener(_anyBind, true, _port, logger, false);

                            if (listener != null)
                            {
                                listener = new AggregateNetworkListener(listener, ipv6Listener);
                            }
                            else
                            {
                                listener = ipv6Listener;
                            }
                        }
                    }
                    else
                    {
                        if (NetUtils.OSSupportsIPv4)
                        {
                            listener = new UdpNetworkListener(_anyBind, false, _port, _enableBroadcast, logger);
                        }

                        if (_ipv6Bind && NetUtils.OSSupportsIPv6)
                        {
                            INetworkListener ipv6Listener = new UdpNetworkListener(_anyBind, true, _port, _enableBroadcast, logger);

                            if(listener != null)
                            {
                                listener = new AggregateNetworkListener(listener, ipv6Listener);
                            }
                            else
                            {
                                listener = ipv6Listener;
                            }
                        }
                    }

                    if (listener == null)
                    {
                        throw new NetServiceException(CANAPE.Documents.Properties.Resources.NetServiceDocument_CannotSetupListener);
                    }

                    ret = new ProxyNetworkService(
                        _packets,
                        listener,
                        _netGraph == null ? BuildDefaultProxyFactory() : _netGraph.Factory, logger, _globalMeta, _history,
                        _credentials, server, client, null, Timeout.Infinite, false);

                    ret.DefaultBinding = NetworkLayerBinding.Server;
                }
                catch (SocketException ex)
                {
                    throw new NetServiceException(Properties.Resources.NetServerDocument_ErrorCreatingServer, ex);
                }
                catch (IOException ex)
                {
                    throw new NetServiceException(Properties.Resources.NetServerDocument_ErrorCreatingServer, ex);
                }

                return ret;
            }
        }
コード例 #2
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="listener">The network listener</param>
 /// <param name="ep">The destination endpoint</param>
 public UdpServerDataAdapter(UdpNetworkListener listener, IPEndPoint ep)
 {
     _listener = listener;
     _ep = ep;
     Description = _ep.ToString();
 }