/// <summary>Publishes.</summary> /// /// <param name="queueName"> Name of the queue.</param> /// <param name="message"> The message.</param> /// <param name="client"> .</param> /// <param name="sequenceID">Identifier for the sequence.</param> public void Publish(string queueName, byte[] message, Socket client, uint sequenceID) { var words = new byte[][] { Encoding.UTF8.GetBytes("publish"), Encoding.UTF8.GetBytes(queueName), message }; var sendToClient = PacketCodec.EncodePacket(false, true, sequenceID, words); Send(sendToClient, client); }
/// <summary> /// Processes a received packet. /// </summary> /// <param name="packet">The packet.</param> /// <param name="client"></param> /// <param name="userToken"></param> void ProcessPacket(byte[] packet, Socket client, ClientSocketState userToken) { var packetObj = PacketCodec.DecodePacket(packet); #if !SILVERLIGHT var type = Type.GetType(Encoding.UTF8.GetString(packetObj.Words[0])); #else var bytes = packetObj.Words[0]; var type = Type.GetType(Encoding.UTF8.GetString(bytes, 0, bytes.Length)); #endif if (messageHandlers.ContainsKey(type)) { messageHandlers[type].Process(new ProcessingClient(packetObj, client, this)); } }
/// <summary> /// Processes a received packet. /// </summary> /// <param name="packet">The packet.</param> /// <param name="userToken"></param> void ProcessPacket(byte[] packet, ClientSocketState userToken) { var packetObj = PacketCodec.DecodePacket(packet); if (_registeredCallbacks.ContainsKey(packetObj.Sequence)) { var callback = _registeredCallbacks[packetObj.Sequence]; _registeredCallbacks.Remove(packetObj.Sequence); if (packetObj.Words.Length < 3) { callback(this, null); } else { callback(this, packetObj.Words[2]); } } }
/// <summary> /// Sends message to the server. /// </summary> /// <param name="words">Words to send.</param> protected virtual void InternalSend(byte[][] words) { if (!Connected) { LastException = new NotConnectedException(); throw LastException; } var packet = PacketCodec.EncodePacket(false, false, _sequenceID++, words); try { var sendEventArgs = new SocketAsyncEventArgs(); sendEventArgs.Completed += new EventHandler <SocketAsyncEventArgs>(sendEventArgs_Completed); sendEventArgs.SetBuffer(packet, 0, packet.Length); _sock.SendAsync(sendEventArgs); } catch (Exception ex) { Disconnect(); LastException = ex; throw LastException; } }