Example #1
0
 public byte[][] ReadAll(string key)
 {
     if (D3BReceive == null || !D3BReceive.Contains(key))
     {
         return(null);
     }
     try
     {
         return(D3BReceive.Get(key).ReadAll());
     }
     catch
     {
         return(null);
     }
 }
Example #2
0
        public bool SetReceiver(string key, byte[] data)
        {
            if (D3BReceive == null || !D3BReceive.Contains(key) || key.IsNullOrEmpty() || data.IsNullOrEmpty())
            {
                return(false);
            }

            try
            {
                D3BReceive.Get(key).Write(data);
                return(true);
            }
            catch
            {
                return(false);
            }
        }
Example #3
0
 public byte[] Read(string key)
 {
     if (D3BReceive == null || !D3BReceive.Contains(key))
     {
         return(null);
     }
     try
     {
         byte[] read;
         D3BReceive.Get(key).Read(out read);
         return(read);
     }
     catch
     {
         return(null);
     }
 }
Example #4
0
        private static void ReadCallback(IAsyncResult IAR)
        {
            StateObject state     = (StateObject)IAR.AsyncState;
            Socket      handler   = state.workSocket;
            int         bytesRead = 0;

            if (!handler.Connected)
            {
                return;
            }
            try
            {
                bytesRead = handler.EndReceive(IAR);
            }
            catch
            {
                return;
            }

            if (bytesRead <= 0)
            {
                return;
            }

            System.String content = System.String.Empty;
            state.sb.Append(Encoding.ASCII.GetString(state.buffer, 0, bytesRead));
            content = state.sb.ToString();


            if (content.IndexOf(TcpAsyncCommon.EOM) < 0)
            {
                if (content.Length < StateObject.BufferSize / 2)
                {
                    try
                    {
                        handler.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0, new AsyncCallback(ReadCallback), state);
                    }catch (Exception e)
                    {
                        ExceptionBuffer.Add(e);
                    }
                }
                else
                {
                    state.sb.Clear();
                    //state.buffer = new byte[StateObject.BufferSize];
                    return;
                }
            }

            state.sb.Clear();
            //state.buffer = new byte[StateObject.BufferSize];
            List <string> Packets = content.SplitSafe(TcpAsyncCommon.EOM).ToList();

            if (Packets.Count > 0)
            {
                foreach (string packet in Packets)
                {
                    string subPacket = packet;
                    if (subPacket == null)
                    {
                        subPacket = "";
                    }
                    else
                    {
                        subPacket = subPacket.Replace(@"\\", @"\");
                    }

                    if (!D3BReceive.Contains(state.key))
                    {
                        return;
                    }
                    else
                    {
                        D3BReceive.Get(state.key).Set(subPacket);
                    }
                    //Thread.Sleep(1);
                }
            }
        }