Beispiel #1
0
        /// <summary>
        /// This is the method which will run a thread
        /// forever listening for incoming data
        /// </summary>
        private void WaitForData()
        {
            try
            {
                Debugger.Log(0, "1", "\nProtocol::WaitForData(): Entering...");

                SocketPacket l_socketPacket = new SocketPacket(this.m_oIncomingDataSocket);

                Debugger.Log(0, "1", "\nProtocol::WaitForData(): Attempting to Receive data.");

                EndPoint ep = Protocol.LocalEndPoint();

                // begins a connectionless asynchronous data transfer
                this.m_oIncomingDataSocket.BeginReceiveFrom(
                    l_socketPacket.DataBuffer,
                    0,
                    SocketPacket.BUFFER_SIZE,
                    0,
                    ref ep,
                    new AsyncCallback(OnDataReceived),
                    l_socketPacket);
            }
            catch (SocketException se)
            {
                MessageBox.Show(se.Message);
            }
            finally
            {
                Debugger.Log(0, "1", "\nProtocol::WaitForData(): Exiting...");
            }
        }
Beispiel #2
0
        /// <summary>
        /// Sends data assynchronously through the provided socket
        /// </summary>
        private void SendData(
            Message _oPacket,
            Socket _socket)
        {
            try
            {
                SocketPacket l_oSockPacket = new SocketPacket(_socket);
                l_oSockPacket.DataBuffer = ObjectByteArrayConverter.ObjectToByteArray(_oPacket);

                _socket.BeginSendTo(
                    l_oSockPacket.DataBuffer,
                    0,
                    SocketPacket.BUFFER_SIZE,
                    SocketFlags.None,
                    this.m_ipOutgoingHost,
                    this.OnDataSent,
                    l_oSockPacket);
            }
            catch (SocketException se)
            {
                MessageBox.Show(se.Message);
            }
        }