Esempio n. 1
0
        /// <summary>
        /// Send binary data to the server
        /// </summary>
        /// <param name="sendBuf">Buffer with the data to be sent</param>
        /// <param name="nrBytesToSend">Number of bytes to send from the buffer</param>
        /// <param name="receiveBuf">Buffer where the reply is to be stored</param>
        /// <returns></returns>
        public bool SendData(byte[] sendBuf, int nrBytesToSend, byte[] receiveBuf)
        {
            Received = false;
            if ((State)SM.CurrentState != State.Connected)
            {
                return(false);
            }
            try
            {
                RCVTimeout = false;
                SendTimer.Restart();


                ServerSocket.BeginSend(sendBuf, 0, nrBytesToSend, SocketFlags.None, new AsyncCallback(SendCallback), ServerSocket);
                ServerSocket.BeginReceive(receiveBuf, 0, receiveBuf.Length, 0, new AsyncCallback(ReceiveCallback), ServerSocket);
                return(true);
            }
            catch
            {
                SendTimedOut = true; //when the send fails, the receive timout can be called immediately
                return(false);
            }
        }