示例#1
0
        public void Connect(IpEndpoint ipEndpoint)
        {
            _ipEndpoint = Converter.Convert(ipEndpoint);
            _socket.Connect(_ipEndpoint);
#pragma warning disable 618
            var socketLocalEndPoint = (IPEndPoint)_socket.LocalEndPoint;
            LocalIpEndpoint = new IpEndpoint(new IpAddress((uint)socketLocalEndPoint.Address.Address), socketLocalEndPoint.Port);
#pragma warning restore 618
        }
示例#2
0
        public UdpListener(IpEndpoint ipEndPoint)
        {
            _socket = SocketFactory.Create();
            _socket.Bind(new IPEndPoint(ipEndPoint.IpAddress.Ipv4Address, ipEndPoint.Port));
            _anyEndPoint = new IPEndPoint(IPAddress.Any, 0);
#pragma warning disable 618
            var socketLocalEndPoint = (IPEndPoint)_socket.LocalEndPoint;
            LocalIpEndpoint = new IpEndpoint(new IpAddress((uint)socketLocalEndPoint.Address.Address), socketLocalEndPoint.Port);
#pragma warning restore 618
        }
示例#3
0
        public int Receive(byte[] buffer, int offset, int count, out IpEndpoint ipEndpoint)
        {
            EndPoint endpoint = _anyEndPoint;
            int      read;

            try
            {
                read = _socket.ReceiveFrom(buffer, offset, count, SocketFlags.None, ref endpoint);
            }
            catch (SocketException socketException)
            {
                // TODO: consider exceptions for bugs only
                // TODO: this fails when remote is closed?!?
                throw new UdpSocketException(socketException.Message, socketException.ErrorCode);
            }
            var ipEndPoint2 = ((IPEndPoint)endpoint);

#pragma warning disable 618
            ipEndpoint = new IpEndpoint(new IpAddress((uint)ipEndPoint2.Address.Address), ipEndPoint2.Port);
#pragma warning restore 618
            return(read);
        }
示例#4
0
 public void Connect(IpEndpoint ipEndpoint)
 {
     BaitAndSwitch.Throw();
 }
示例#5
0
 public UdpClient()
 {
     LocalIpEndpoint = new IpEndpoint(IpAddress.AnyAddress, 0);
     BaitAndSwitch.Throw();
 }
示例#6
0
 public static IPEndPoint Convert(IpEndpoint ipEndpoint)
 {
     return(new IPEndPoint(ipEndpoint.IpAddress.Ipv4Address, ipEndpoint.Port));
 }
示例#7
0
 public UdpSend(Socket socket, IpEndpoint ipEndPoint)
 {
     _socket     = socket;
     _ipEndPoint = Converter.Convert(ipEndPoint);
 }
示例#8
0
 public IUdpSend ForkSendTo(IpEndpoint ipEndPoint)
 {
     return(new UdpSend(_socket, ipEndPoint));
 }