public void sendMessage(Command command) { multicastSocket.Send(command.serialize()); }
public void sendCommand(Command command) { try{ int amount=0; byte[] commandBuffer = command.serialize(); while (amount < commandBuffer.Length) { int messageSize = Math.Min(PlanckDBConstants.MAX_TCP_MESSAGE_SIZE, commandBuffer.Length - amount); socket.GetStream().Write(commandBuffer, amount, messageSize); socket.GetStream().Flush(); amount+=messageSize; } amount=0; while (amount < PlanckDBConstants.SIZE_OF_INT) { int read = socket.GetStream().Read(buffer, amount, 4 - amount); if(read<0){ tcpConversationHolder.handleTcpConnectionFailure(this); return; } amount+= read; } int commandSize = SerializationUtils.byteArrayToInt(buffer, 0); amount=0; commandBuffer = new byte[commandSize - PlanckDBConstants.SIZE_OF_INT]; while(amount<commandSize- PlanckDBConstants.SIZE_OF_INT){ amount += socket.GetStream().Read(commandBuffer, amount, commandSize - (amount + PlanckDBConstants.SIZE_OF_INT)); } Command resultCommand = AbstractCommand.deSerialize(commandBuilder, commandBuffer, 0, commandBuffer.Length); resultCommand.fill(command); } catch (IOException e) { throw new PlanckDBException(CommandStatus.unsupported,"TCP connection failure due to IOException : "+e.Message); } }