当前位置: 首页>>代码示例>>C#>>正文


C# Socket.BeginReceiveFrom方法代码示例

本文整理汇总了C#中System.Net.Sockets.Socket.BeginReceiveFrom方法的典型用法代码示例。如果您正苦于以下问题:C# Socket.BeginReceiveFrom方法的具体用法?C# Socket.BeginReceiveFrom怎么用?C# Socket.BeginReceiveFrom使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Net.Sockets.Socket的用法示例。


在下文中一共展示了Socket.BeginReceiveFrom方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: btnConnect_Click

        //metodo eseguito al click sul pulsante connetti
        private void btnConnect_Click(object sender, EventArgs e)
        {
            //vengono memorizzati il nome utente e
            //viene aggiornata la casella di testo
            _userName = txtUserName.Text.Trim();
            _setText = SetText;

            //viene creato e riempito un pacchetto di richiesta di join alla chat
            Packet sendData = new Packet();
            sendData.DataIdentifier = DataTypeIdentifier.Login;
            sendData.UserName = _userName;

            //viene creato un Socket UDP
            _clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);

            //viene creato un oggetto contenente l'indirizzo IP e la porta del server
            IPAddress serverIP = IPAddress.Parse(txtServerAddress.Text);
            int serverPort = int.Parse(txtServerPort.Text);
            _epServer = new IPEndPoint(serverIP, serverPort);

            //il pacchetto creato viene convertito in un'array di byte
            _dataStream = sendData.ToByteArray();

            //il pacchetto creato viene spedito al server
            _clientSocket.BeginSendTo(_dataStream, 0, _dataStream.Length, SocketFlags.None, _epServer, SendData, null);

            //tutti gli oggetti vengono sempre passati per referenza
            //il client si mette ora in ascolto dei messaggi provenienti dal server
            EndPoint ep = _epServer;
            _dataStream = new byte[Properties.Settings.Default.MAX_PACKET_LENGTH];
            _clientSocket.BeginReceiveFrom(_dataStream, 0, _dataStream.Length, SocketFlags.None, ref ep, ReceiveData, null);
        }
开发者ID:Onhyro,项目名称:esercizi-tecnologie-2015-2016,代码行数:33,代码来源:frmClientUDP.cs

示例2: StartListening

        public void StartListening()
        {
            EndPoint localEp = ( EndPoint )_iep;
            Socket listener = new Socket( AddressFamily.InterNetwork,
                                          SocketType.Dgram,
                                          ProtocolType.Udp );
            try
            {
                listener.Bind( localEp );
                while ( true )
                {
                    allDone.Reset();
                    StateObject so = new StateObject();
                    so.workSocket = listener;
                    Console.WriteLine( "Waiting for a connection..." );
                    IAsyncResult result =
                    listener.BeginReceiveFrom( so.buffer,
                                              0,
                                              StateObject.BUFFER_SIZE,
                                              SocketFlags.None,
                                              ref localEp,
                                              new AsyncCallback( this.OnReceive ), so );
                    allDone.WaitOne();
                }

            }
            catch ( Exception e )
            {
                Console.WriteLine( e.ToString() );
            }
        }
开发者ID:wirepair,项目名称:GHAST_priv8,代码行数:31,代码来源:UDPServerService.cs

示例3: CreateListener

 private IAsyncResult CreateListener()
 {
     _testSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
     _testSocket.Bind(new IPEndPoint(IPAddress.Any, 12721));
     byte[] inbuffer = _bufferPool.Dequeue();
     EndPoint ep = new IPEndPoint(IPAddress.Any, 1234);
     return _testSocket.BeginReceiveFrom(inbuffer, 0, inbuffer.Length, SocketFlags.None, ref ep, null, null);
 }
开发者ID:jgauffin,项目名称:SipSharp,代码行数:8,代码来源:UdpTransportTest.cs

示例4: Bf2Available

        public Bf2Available()
        {
            // Creates an IPEndPoint to reference the IP Address and port number of the sender.
            EndPoint RemoteIpEndPoint = new IPEndPoint(IPAddress.Any, 0);

            // Bind to local address and begin accepting connections
            UdpSock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            UdpSock.Bind(new IPEndPoint(IPAddress.Loopback, 27900));
            UdpSock.BeginReceiveFrom(buffer, 0, buffer.Length, SocketFlags.None, ref RemoteIpEndPoint, DoReceiveFrom, UdpSock);
        }
开发者ID:BF2Statistics,项目名称:ClientLauncher,代码行数:10,代码来源:Bf2Available.cs

示例5: process

 /**
  * Connect and receive data for the thread
  */
 public override void process()
 {
     this.receiveSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
     this.bindEndPoint = new IPEndPoint(IPAddress.Parse(this.host), this.port);
     this.recBuffer = new byte[this.BufferSize];
     receiveSocket.Bind(bindEndPoint);
     receiveSocket.BeginReceiveFrom(recBuffer, 0, recBuffer.Length,
         SocketFlags.None, ref bindEndPoint,
         new AsyncCallback(MessageReceivedCallback), (object)this);
 }
开发者ID:arnie-robot,项目名称:PYT,代码行数:13,代码来源:InputThread.cs

示例6: MulticastCommandServer

 public MulticastCommandServer(string uid)
 {
     this.uid = uid;
     this.DscLog = new DscLog();
     this.sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
     EndPoint ep = (EndPoint)(new IPEndPoint(IPAddress.Any, MulticastEP.Port));
     this.sock.Bind(ep);
     this.sock.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.AddMembership, new MulticastOption(MulticastEP.Address));
     Trace.WriteLine(String.Format("Multicast JSON-RPC server: {0}:{1}", MulticastEP.Address, MulticastEP.Port));
     sock.BeginReceiveFrom(dataIn, 0, dataIn.Length, SocketFlags.None, ref ep, new AsyncCallback(ReceiveData), ep);
 }
开发者ID:ajf8,项目名称:marine-radio,代码行数:11,代码来源:MulticastCommandServer.cs

示例7: Start

		public void Start()
		{
			serverSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
			IPEndPoint ipEndPoint = new IPEndPoint(IPAddress.Any, Port);
			serverSocket.Bind(ipEndPoint);

			IPEndPoint ipeSender = new IPEndPoint(IPAddress.Any, 0);
			EndPoint epSender = (EndPoint)ipeSender;

			serverSocket.BeginReceiveFrom(byteData, 0, byteData.Length, SocketFlags.None, ref epSender, new AsyncCallback(OnReceive), epSender);
		}
开发者ID:saeednazari,项目名称:Rubezh,代码行数:11,代码来源:SKDImitatorProcessor.cs

示例8: UdpListener

        /// <summary>
        /// Bind to the
        /// </summary>
        /// <param name="port"></param>
        public UdpListener(IPAddress serverAddress, int port, ServerFilter filter)
        {
            this.filter = filter;

            UDPSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            UDPSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.Broadcast, true);
            UDPSocket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, true);
            UDPSocket.Bind(new IPEndPoint(serverAddress, port));
            EndPoint tempRemoteEP = (EndPoint)sender;
            UDPSocket.BeginReceiveFrom(buff, 0, buff.Length, SocketFlags.None, ref tempRemoteEP, GotUdpMessage, tempRemoteEP);
        }
开发者ID:ISISComputingGroup,项目名称:EPICS-epicssharp,代码行数:15,代码来源:UdpListener.cs

示例9: ProxySocket

        public ProxySocket(int port)
        {
            //Setup the socket and message buffer
            udpSock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            udpSock.Bind(new IPEndPoint(IPAddress.Any, port));
            buffer = new byte[1024];

            //Start listening for a new message.
            EndPoint newClientEP = new IPEndPoint(IPAddress.Any, 0);
            udpSock.BeginReceiveFrom(buffer, 0, buffer.Length, SocketFlags.None, ref newClientEP, DoReceiveFrom, udpSock);
        }
开发者ID:Mesagoppinmypants,项目名称:SWGProxy,代码行数:11,代码来源:ProxySocket.cs

示例10: Start

        public void Start(int port, int buf_len)
        {
            buffer = new byte[buf_len];

            // setup the socket
            socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            socket.Bind(new IPEndPoint(IPAddress.Any, port));

            // start listening
            EndPoint newClientEP = new IPEndPoint(IPAddress.Any, 0);
            socket.BeginReceiveFrom(buffer, 0, buffer.Length, SocketFlags.None, ref newClientEP, new AsyncCallback(DoReceiveFrom), socket);
        }
开发者ID:h0lmes,项目名称:RoboBrainCS,代码行数:12,代码来源:UdpListenerClass.cs

示例11: Start

		public void Start()
		{
			GkDatabase = DescriptorsManager.GkDatabases.FirstOrDefault();

			serverSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
			IPEndPoint ipEndPoint = new IPEndPoint(IPAddress.Any, 1025);
			serverSocket.Bind(ipEndPoint);

			IPEndPoint ipeSender = new IPEndPoint(IPAddress.Any, 0);
			EndPoint epSender = (EndPoint)ipeSender;

			serverSocket.BeginReceiveFrom(byteData, 0, byteData.Length, SocketFlags.None, ref epSender, new AsyncCallback(OnReceive), epSender);
		}
开发者ID:saeednazari,项目名称:Rubezh,代码行数:13,代码来源:GKProcessor.cs

示例12: Start

        public static void Start()
        {
            _thread = new Thread(new ThreadStart(Run));
            _thread.Start();

            _connection = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
            _connection.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, 500);
            _connection.Bind(new IPEndPoint(IPAddress.Any, 0));

            obtainedData = new byte[100 * 1024];
            obtainedIP = new IPEndPoint(IPAddress.Loopback, 12345); // should be useless?
            _connection.BeginReceiveFrom(obtainedData, 0, obtainedData.Length, SocketFlags.None, ref obtainedIP, new AsyncCallback(QueryReceived), null);

            Servers = new Dictionary<IPEndPoint, ServerData>();
        }
开发者ID:h3o66,项目名称:alteriwnet,代码行数:15,代码来源:ServerParser.cs

示例13: AwaitConnectionTimer_Tick

        private void AwaitConnectionTimer_Tick(object sender, EventArgs e)
        {
            if (!_connected)
            {
                LogMessage("Server not found. I am server now!");

                _awaitConnectionTimer.Stop();
                _udpSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
                _udpSocket.Bind(_ipep);
                EndPoint ep = (EndPoint)_ipep;
                _udpSocket.BeginReceiveFrom(_buffer, 0, _buffer.Length, SocketFlags.None, ref ep, new AsyncCallback(ListenerRecieveCallback), _udpSocket);

                TcpServerInit();
            }
        }
开发者ID:Verdungo,项目名称:SNet,代码行数:15,代码来源:ChatClientWindow.xaml.cs

示例14: button1_Click

        private void button1_Click(object sender, EventArgs e)
        {
            if (socket != null)
                return;
            socket=new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.IP);
            socket.Bind(new IPEndPoint(IPAddress.Parse("10.2.21.129"), 100));

            state.workSocket = socket;
            RcptRes = socket.BeginReceiveFrom(state.buffer,
                0,
                StateObject.BufferSize,
                SocketFlags.None,
                ref ClientEP, 
                new AsyncCallback(Receive_Completed), state);            
        }
开发者ID:xs2ranjeet,项目名称:13ns9-1spr,代码行数:15,代码来源:Form1.cs

示例15: AwaitConnectionTimer_Tick

        private void AwaitConnectionTimer_Tick(object sender, EventArgs e)
        {
            LogMessage("Connection timer elapsed.");

            _awaitConnectionTimer.Stop();
            // TODO: а нам это надо?
            if (!_connected)
            {
                _udpSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
                _udpSocket.Bind(_ipep);
                EndPoint ep = (EndPoint)_ipep;
                _udpSocket.BeginReceiveFrom(_buffer, 0, _buffer.Length, SocketFlags.None, ref ep, new AsyncCallback(ListenerRecieveCallback), _udpSocket);
                LogMessage("Waiting for clients...");
            }
        }
开发者ID:Verdungo,项目名称:SNet,代码行数:15,代码来源:MainWindow.xaml.cs


注:本文中的System.Net.Sockets.Socket.BeginReceiveFrom方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。