예제 #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));
 }