Example #1
0
        public ReceiveHandler Send(byte[] command, ReceiveHandler handler)
        {
            Socket s;

            if (handler == null)
            {
                handler = new ReceiveHandler();
                handler.ReceivePackageCount = 0;
            }

            if (!handler.Busy.WaitOne(0)) //Check if this ReceiveHandler object is currently in use.
            {
                throw new Exception("This ReceiveHandler object is currently in use.");
            }

            s = handler.ChannelId == default(Guid) ? SharedSocket : Channels[handler.ChannelId];

            if (s.Connected)
            {
                var e = EventArgsPool.Request();

                e.UserToken = handler;
                handler.Busy.Reset(); //Reset the waithandle for any threads who want to wait on this response.

                e.SetBuffer(command, 0, command.Length);

                if (!s.SendAsync(e))
                {
                    ProcessSocketEvents(s, e);
                }

                return handler;
            }
            else
            {
                throw new Exception("TODO: Add a specific exception. (Not connected exception)");
            }
        }
Example #2
0
 public ReceiveHandler Send(string command, ReceiveHandler handler)
 {
     return Send(Encoding.UTF8.GetBytes(command), handler);
 }
Example #3
0
        public ReceiveHandler Send(Guid channelId, string command, int numOfPackagesToRec = 0)
        {
            var r = new ReceiveHandler();
            r.ReceivePackageCount = numOfPackagesToRec;
            r.ChannelId = channelId;

            return Send(Encoding.UTF8.GetBytes(command), r);
        }
Example #4
0
        public ReceiveHandler Send(Guid channelId, byte[] command, ReceiveCallback callback, int numOfPackagesToRec = 1)
        {
            var r = new ReceiveHandler();
            r.Callback = callback;
            r.ReceivePackageCount = numOfPackagesToRec;
            r.ChannelId = channelId;

            return Send(command, r);
        }
Example #5
0
        public ReceiveHandler Receive(ReceiveHandler handler)
        {
            if (handler == null)
                return null;

            var s = handler.ChannelId == default(Guid) ? SharedSocket : Channels[handler.ChannelId];
            var e = EventArgsPool.Request();

            if (s.Connected)
            {
                if (handler != null)
                {
                    e.UserToken = handler;
                    handler.Busy.Reset(); //Reset the waithandle for any threads who want to wait on this response.
                }

                e.SetBuffer(new byte[0], 0, 0);

                if (!s.ReceiveAsync(e))
                {
                    ProcessSocketEvents(s, e);
                }

                return handler;
            }
            else
            {
                throw new Exception("TODO: Add a specific exception. (Not connected exception)");
            }
        }