public bool Send(uint sequenceId, ICmppMessage message) { lock (_lock) { if (!Connected) { return(false); } try { if (_socket.Poll(0, SelectMode.SelectError) || !_socket.Poll(50000, SelectMode.SelectWrite)) { Disconnect(); return(false); } var buffer = message.ToBytes(); var header = new CmppHead { SequenceId = sequenceId, TotalLength = (uint)(CmppConstants.HeaderSize + buffer.Length), CommandId = message.GetCommandId() }; _socket.Send(header.ToBytes()); _socket.Send(buffer); } catch (Exception ex) { log.ErrorFormat("Error sending {0}. Error: {1}.", message.GetType().Name, ex); Disconnect(); return(false); } return(true); } }
private static void SendMessage(Socket socket, ICmppMessage message) { var buffer = message.ToBytes(); var head = new CmppHead { CommandId = message.GetCommandId(), SequenceId = _seq++, TotalLength = (uint)(CmppConstants.HeaderSize + buffer.Length) }; socket.Send(head.ToBytes()); socket.Send(buffer); }