/// <summary> /// Send bytes to client. /// </summary> /// <param name="data"></param> /// <param name="close"></param> /// <param name="partial"></param> /// <param name="id"></param> protected override void SendToSocket(byte[] data, bool close, bool partial = false, int id = -1) { var state = GetClient(id); try { if (state != null) { if (!IsConnected(state.Id)) { //Sets client with id to disconnected RaiseClientDisconnected(state, DisconnectReason.Unknown); throw new Exception("Message failed to send because the destination socket is not connected."); } else { state.Close = close; BlockingMessageQueue.Enqueue(new MessageWrapper(data, state, partial)); } } } catch (Exception ex) { RaiseMessageFailed(state, data, ex); } }
protected override void SendToSocket(byte[] payLoad, bool close, bool partial = false, int id = -1) { var state = GetClient(id); try { if (state == null) { throw new Exception("Client does not exist."); } if (!IsConnected(id)) { RaiseClientDisconnected(state, DisconnectReason.Unknown); Close(id); throw new Exception("Message failed to send because the destination socket is not connected."); } state.Close = close; BlockingMessageQueue.Enqueue(new MessageWrapper(payLoad, state, partial)); } catch (Exception ex) { RaiseMessageFailed(state, payLoad, ex); } }
//Send partial message protected override void SendBytesPartial(byte[] bytes, int id) { var state = GetClient(id); try { if (state == null) { throw new Exception("Client does not exist."); } if (!IsConnected(state.Id)) { //Sets client with id to disconnected ClientDisconnectedInvoke(state.Id); Close(state.Id); InvokeMessageFailed(id, bytes, new Exception("Message failed to send because the destination socket is not connected.")); } BlockingMessageQueue.Enqueue(new Message(bytes, MessageType.Partial, state)); } catch (Exception ex) { InvokeMessageFailed(id, bytes, ex); } }
protected override void SendToSocket(byte[] data, bool close, bool partial = false, int id = -1) { //If socket has been ordered to close, prevent adding new messages to queue if (CloseClient) { return; } CloseClient = close; BlockingMessageQueue.Enqueue(new MessageWrapper(data, partial)); }
//Sends bytes of file protected override void SendBytesPartial(byte[] bytes, int id) { try { BlockingMessageQueue.Enqueue(new Message(bytes, MessageType.Partial)); } catch (Exception ex) { InvokeMessageFailed(bytes, ex); } }
protected override void SendToSocket(byte[] bytes, bool close, bool partial = false, int id = -1) { try { CloseClient = close; BlockingMessageQueue.Enqueue(new MessageWrapper(bytes, partial)); } catch (Exception ex) { RaiseMessageFailed(null, bytes, ex); } }
/// <summary> /// Sends data to server /// </summary> /// <param name="bytes"></param> /// <param name="close"></param> protected override void SendBytes(byte[] bytes, bool close) { try { CloseClient = close; BlockingMessageQueue.Enqueue(new Message(bytes, MessageType.Complete)); } catch (Exception ex) { InvokeMessageFailed(bytes, ex); } }
//Sends bytes of file protected override void SendBytesPartial(byte[] bytes, int id) { try { if (!IsConnected()) { DisposeSslStream(); Close(); InvokeMessageFailed(bytes, new Exception("Server socket is not connected.")); } else { BlockingMessageQueue.Enqueue(new Message(bytes, MessageType.Partial)); } } catch (Exception ex) { InvokeMessageFailed(bytes, ex); } }
//Sends bytes to corresponding server. protected override void SendBytes(byte[] bytes, bool close) { try { if (!IsConnected()) { DisposeSslStream(); InvokeDisconnected(this); Close(); InvokeMessageFailed(bytes, new Exception("Server socket is not connected.")); } else { CloseClient = close; BlockingMessageQueue.Enqueue(new Message(bytes, MessageType.Complete)); } } catch (Exception ex) { InvokeMessageFailed(bytes, ex); } }
protected override void SendToSocket(byte[] data, bool close, bool partial = false, int id = -1) { CloseClient = close; BlockingMessageQueue.Enqueue(new MessageWrapper(data, partial)); }