/// <summary> /// Connects to the remote host /// </summary> /// <param name="Protocol">The protocol to be used</param> public override void Connect(SocketProtocol Protocol = SocketProtocol.TcpStream) { if (Protocol != SocketProtocol.TcpStream) { throw new NotImplementedException(); } this._NetworkInterface.OpenSocket(this._Hostname, this._Port); }
internal static Socket For(SocketProtocol socketProtocol) { return(socketProtocol switch { SocketProtocol.IP => ForIp(), SocketProtocol.Udp => ForUdp(), _ => throw new InvalidOperationException($"Unknown {nameof(SocketProtocol)} value {socketProtocol} specified."), });
/// <summary> /// Initializes a new instance of the <see cref="SocketTransport"/> class. /// </summary> /// <param name="endPointSource">The <see cref="IEndPointSource"/> to use.</param> /// <param name="socketProtocol">Udp or Ip sockets</param> /// <exception cref="ArgumentNullException"> /// <paramref name="endPointSource"/> is <see langword="null"/>. /// </exception> public SocketTransport(IEndPointSource endPointSource, SocketProtocol socketProtocol) { _endpointSource = endPointSource ?? throw new ArgumentNullException(nameof(endPointSource)); if (!Enum.IsDefined(typeof(SocketProtocol), socketProtocol)) { throw new ArgumentOutOfRangeException(nameof(socketProtocol), socketProtocol, $"Invalid {nameof(SocketProtocol)} value specified."); } _socketProtocol = socketProtocol; }
internal static Socket For(SocketProtocol socketProtocol) { switch (socketProtocol) { case SocketProtocol.IP: return(ForIp()); case SocketProtocol.Udp: return(ForUdp()); default: throw new InvalidOperationException($"Unknown {nameof(SocketProtocol)} value {socketProtocol} specified."); } }
/// <summary> /// Connects to the remote host /// </summary> /// <param name="Protocol">The protocol to be used</param> public override void Connect(SocketProtocol Protocol = SocketProtocol.TcpStream) { // Creates a new socket object if (Protocol == SocketProtocol.TcpStream) this._Sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); else this._Sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); // Resolves the hostname to an IP address IPHostEntry address = Dns.GetHostEntry(this._Hostname); // Creates the new IP end point EndPoint Destination = new IPEndPoint(address.AddressList[0], (int)this._Port); // Connects to the socket this._Sock.Connect(Destination); this._Closed = false; }
/// <summary> /// 构造函数 /// </summary> /// <param name="protocol">类型</param> /// <param name="ipAddress">ip地址</param> /// <param name="port">端口</param> /// <param name="maxQueuedConnections">Socket最多可容纳的等待接受的传入连接数</param> /// 时间:2016/6/7 11:35 /// 备注: public ScoketAppServer(SocketProtocol protocol, string ipAddress, ushort port, int maxQueuedConnections) { ValidateOperator.Begin().NotNullOrEmpty(ipAddress, "Ip地址").IsIp(ipAddress, "Ip地址"); IPAddress _ipAddress; if (IPAddress.TryParse(ipAddress, out _ipAddress)) { this.Endpoint = new IPEndPoint(_ipAddress, port); } else { throw new ArgumentException("未能识别的Ip地址。"); } this.Protocol = protocol; this.Port = port; this.MaxQueuedConnections = maxQueuedConnections; }
public static async Task Can_Send_Metrics_To_StatsD_Using_Udp( string host, SocketProtocol socketProtocol) { Skip.If(Environment.GetEnvironmentVariable("CI") == null, "By default, this test is only run during continuous integration."); // Arrange var config = new StatsDConfiguration { Host = host, Prefix = Guid.NewGuid().ToString().Replace("-", string.Empty, StringComparison.Ordinal), SocketProtocol = socketProtocol, }; using var publisher = new StatsDPublisher(config); // Act and Assert await AssertMetrics(config, publisher); }
/// <summary> /// Connects to the remote host /// </summary> /// <param name="Protocol">The protocol to be used</param> public override void Connect(SocketProtocol Protocol = SocketProtocol.TcpStream) { // Creates a new socket object if (Protocol == SocketProtocol.TcpStream) { this._Sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); } else { this._Sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); } // Resolves the hostname to an IP address IPHostEntry address = Dns.GetHostEntry(this._Hostname); // Creates the new IP end point EndPoint Destination = new IPEndPoint(address.AddressList[0], (int)this._Port); // Connects to the socket this._Sock.Connect(Destination); this._Closed = false; }
/// <summary> /// Connects to the remote host /// </summary> /// <param name="Protocol">The protocol to be used</param> public abstract void Connect(SocketProtocol Protocol = SocketProtocol.TcpStream);
/// <summary> /// Connects to the remote host /// </summary> /// <param name="Protocol">The protocol to be used</param> public override void Connect(SocketProtocol Protocol = SocketProtocol.TcpStream) { if (Protocol != SocketProtocol.TcpStream) throw new NotImplementedException(); this._NetworkInterface.OpenSocket(this._Hostname, this._Port); }
/// <summary>Sets the socket protocol.</summary> /// <param name="protocol">The desired protocol.</param> public void SetProtocol(SocketProtocol protocol) { this.EnterCommandMode(); this.ExecuteCommand("set ip protocol " + protocol.ToString()); this.ExitCommandMode(); }
/// <summary> /// 构造函数 /// </summary> /// <param name="protocol">类型</param> /// <param name="ipAddress">ip地址</param> /// 时间:2016/6/7 11:35 /// 备注: public ScoketAppServer(SocketProtocol protocol, string ipAddress) : this(protocol, ipAddress, 9888, 1024) { }
public ConnectedSocketPool(EndPoint endPoint, SocketProtocol socketProtocol, int initialSize) { EndPoint = endPoint; _socketProtocol = socketProtocol; PrePopulateSocketPool(initialSize); }
public static extern bool wirefox_peer_bind(IntPtr handle, SocketProtocol protocol, [MarshalAs(UnmanagedType.U2)] ushort port);
/// <summary>Bind this peer to a local network interface.</summary> /// <remarks> /// This function must be called before initiating or accepting new connections. The Peer cannot receive /// data from the network unless the peer is bound.After this function is called, you can only use the /// protocol family specified in <paramref name="protocol"/> for any incoming or outgoing connections.</remarks> /// <param name="protocol">Indicates the socket family to use for this Peer (either IPv4 or IPv6).</param> /// <param name="port">Specifies the local port to bind to. Specify 0 to have the system assign a random port.</param> /// <returns>True on success; false if the specified port is already in use, or if you have insufficient /// system privileges to bind, or if the system is otherwise being difficult.</returns> public bool Bind(SocketProtocol protocol, ushort port) { return(NativeMethods.wirefox_peer_bind(m_handle, protocol, port)); }