Beispiel #1
0
        private bool Send()
        {
            byte[] data;

            if (SLClient == null ||
                DBSend == null ||
                !SLClient.Connected ||
                DBSend.IsAllRead ||
                !DBSend.Read(out data))
            {
                return(false);
            }


            byte[] result_data = TcpAsyncCommon.CreatePacket(data, PacketMode);// result.ToArray();

            if (result_data.IsNullOrEmpty())
            {
                return(false);
            }

            int sent = 0;
            int size = result_data.Length;

            SendTimeout.Reset();
            do
            {
                int packet = size - sent;
                if (packet > TcpAsyncServer.PacketSizeTCP)
                {
                    packet = TcpAsyncServer.PacketSizeTCP;
                }
                try
                {
                    sent += SLClient.Send(result_data, sent, packet, SocketFlags.None);
                    //Thread.Sleep(1);
                }
                catch (Exception ex)
                {
                    Exceptions.Write(ex);
                    this.StopClient();
                    return(false);
                }

                if (SendTimeout.IsTriggered)
                {
                    return(false);
                }
            }while (sent < size);

            return(true);
        }
Beispiel #2
0
        private bool Send()
        {
            if (!SLClient.Connected || !DBSend.IsDataAvalaible)
            {
                return(false);
            }

            string sData = DBSend.Get(false); //Don't increment data, becouse it is not certain at this point, if it will be send

            if (sData == null)
            {
                return(false);
            }

            sData.Replace(@"\", @"\\");
            sData = sData + TcpAsyncCommon.EOM;

            byte[] baData = Encoding.ASCII.GetBytes(sData);

            if (baData.Length > 1024)
            {
                throw new Exception("Exception in Send() method, packet size is to large.");
            }

            try
            {
                SLClient.Send(baData);
            }
            catch
            {
                return(false);
            }

            DBSend.IndexerIcrement(); //Increment indexer, becouse data was successfully send.
            return(true);
        }