diff --git a/ompi/communicator/comm_init.c b/ompi/communicator/comm_init.c
index 23fe6646e16ad55960efc7a8df804c3003735def..c519f6728100a67790a8b18692ef873f01657519 100644
--- a/ompi/communicator/comm_init.c
+++ b/ompi/communicator/comm_init.c
@@ -32,6 +32,7 @@
 
 #include "ompi_config.h"
 
+#include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <sys/socket.h>
@@ -39,6 +40,7 @@
 #include <sys/un.h>
 #include <unistd.h>
 #include <string.h>
+#include <endian.h>
 
 #include "opal/util/bit_ops.h"
 #include "opal/util/info_subscriber.h"
@@ -159,21 +161,23 @@ static int get_modified_ranks(uint32_t jobid, uint32_t vpid, size_t size, opal_v
             "{\"msg_type\": 128, \"msg_data\": \"%d,%u,%u,%zu%s\"}",
             pid, vpid, jobid, size, vrm_jobid_with_leading_comma);
 
-    // TODO: endianness
     uint32_t msg_length = strlen(info_to_send) + 1;
-    if (send(socket_fd, &msg_length, sizeof(msg_length), 0) < 0) {
+    // Ensure that little endian is used for communinication (by convention with server)
+    uint32_t le_msg_length = htole32(msg_length);
+    if (send(socket_fd, &le_msg_length, sizeof(le_msg_length), 0) < 0) {
         errorExit("send");
     }
     if (send(socket_fd, info_to_send, msg_length, 0) < 0) {
         errorExit("send");
     }
 
-    char rank_to_recv[BUFFLEN];
-    memset(rank_to_recv, 0, BUFFLEN);
+    uint32_t le_answer_length = 0;
     // drop (later overwrite) the length since it is not needed
-    recv(socket_fd, rank_to_recv, BUFFLEN-1, 0);
+    recv(socket_fd, &le_answer_length, sizeof(le_answer_length), 0);
+    uint32_t answer_length = le32toh(le_answer_length);
+    char * rank_to_recv = calloc (answer_length, sizeof(char));
     // receive the actual message content
-    recv(socket_fd, rank_to_recv, BUFFLEN-1, 0);
+    recv(socket_fd, rank_to_recv, answer_length, 0);
     printf("Received from server: %s\n", rank_to_recv);
 
     // look for msg_data field in JSON string
@@ -191,6 +195,8 @@ static int get_modified_ranks(uint32_t jobid, uint32_t vpid, size_t size, opal_v
         modified_ranks[i] = strtoul(next_digit, &first_non_digit, 10);
     }
 
+    free(rank_to_recv);
+
     // // Print modified_ranks array for debugging purposes
     // printf("modified_ranks: [");
     // for (size_t i = 0; i < size; i++) {
diff --git a/rank-swapper-agent/locserv.c b/rank-swapper-agent/locserv.c
index 7c11f2867d12a94678db33eb4a38fe6fdf4af5cd..99f8de227687a7f66a73df231b6e62a34b9fcc1d 100644
--- a/rank-swapper-agent/locserv.c
+++ b/rank-swapper-agent/locserv.c
@@ -17,6 +17,7 @@
 #include <sys/un.h>
 #include <time.h>
 #include <unistd.h>
+#include <endian.h>
 
 #define MAX_CONNECTIONS 10
 #define BUFFLEN  256
@@ -73,7 +74,7 @@ int main(void) {
     
         // read the length and discard it (by overwriting it next)
         recv(session_fd, client_message, sizeof(uint32_t), 0);
-        printf("Length-Msg: %s\n", client_message);
+        printf("Length-Msg: %u\n", le32toh(*(uint32_t *)client_message));
         // since recv() seems to be atomar, no concurrent behaviour must be
         // considered
         recv(session_fd, client_message, BUFFLEN, 0);
@@ -106,10 +107,11 @@ int main(void) {
         snprintf(rankString, BUFFLEN, "{\"msg_type\": 0, \"msg_data\": \"%s\"}", rankList);
         // the length must be send first to emulate the behaviour of the actual TCP server but it
         // gets discarded on client side anyway so it does not need to make sense
-        uint32_t unneeded_length = 0;
-        send(session_fd, &unneeded_length, sizeof(uint32_t), 0);
+        uint32_t needed_length = strlen(rankString) + 1;
+        uint32_t le_needed_length = le32toh(needed_length);
+        send(session_fd, &le_needed_length, sizeof(uint32_t), 0);
         // send the actual message
-        if (send(session_fd, rankString, BUFFLEN, 0) < 0) {
+        if (send(session_fd, rankString, needed_length, 0) < 0) {
                 errorExit("send");
         }
         printf("Send Rank: %s\n\n", rankString);