public void Send(IPCMessage message) { using (BinaryWriter writer = new BinaryWriter(_client, Encoding.Default, true)) { writer.Write(message.Serialize()); writer.Flush(); } }
public void ReadCallback(IAsyncResult result) { int bytesRead; try { bytesRead = _client.EndRead(result); if (bytesRead == 0) { throw new IOException("bytesRead == 0"); } } catch (IOException) { if (OnDisconnected != null) { OnDisconnected(this); } return; } byte opCode = _buffer[0]; if (_callbacks.ContainsKey(opCode)) { IPCCallback callback = _callbacks[opCode]; IPCMessage message = (IPCMessage)Activator.CreateInstance(callback.Type); message.Deserialize(_buffer); if (message is IPCResponseMessage response) { if (_pendingTransactions.ContainsKey(response.TransactionId)) { _pendingTransactions[response.TransactionId].Response = response; _pendingTransactions[response.TransactionId].Set(); _pendingTransactions.Remove(response.TransactionId); } } if (callback.Callback != null) { callback.Callback(this, message); } } BeginRead(); }
private void ReadCallback(IAsyncResult result) { int bytesRead; try { bytesRead = _server.EndRead(result); if (bytesRead == 0) { throw new IOException("bytesRead == 0"); } } catch (IOException) { if (OnDisconnected != null) { OnDisconnected(this); } return; } byte opCode = _buffer[0]; if (_callbacks.ContainsKey(opCode)) { IPCCallback callback = _callbacks[opCode]; IPCMessage message = (IPCMessage)Activator.CreateInstance(callback.Type); message.Deserialize(_buffer); if (callback.Callback != null) { callback.Callback(this, message); } } BeginRead(); }