I have two processes (one in C and another in Python) that comunicate between them by sending 1-byte OP codes.
I was using sockets (AF_UNIX, SOCK_STREAM), however, when I was looking into the Sockets buffer I saw :
ss -nx | grep 145115781
u_str ESTAB 0 768 my_socket 145253942 *145115781
u_str ESTAB 1 0 * 145115781 *145253942
as you can see the Send-Q of the socket is 768 even though I have sent 1 byte (the only explanation to it I found here) it looks not efficient to send 768 bytes buffer for effective data of one byte.
what is the best way to do it? and if you have a better explanation for the 768 bytes I would be glad to here is.
server:
struct sockaddr_un local;
int len;
if((server_sockfd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
{
perror("Error creating server socket");
exit(1);
}
local.sun_family = AF_UNIX;
strcpy(local.sun_path, SOCK_PATH);
unlink(local.sun_path);
len = strlen(local.sun_path) + sizeof(local.sun_family);
if(bind(server_sockfd, (struct sockaddr *)&local, len) == -1)
{
perror("binding");
exit(1);
}
if(listen(server_sockfd, 5) == -1)
{
perror("listen");
exit(1);
}
printf("Listening...\n");
fflush(stdout);
if((client_sockfd = accept(server_sockfd, (struct sockaddr *)&remote, &t)) == -1)
{
perror("accept");
exit(1);
}
int i;
for(i=0; i < SIZE_DATA; i++){
buff[0] = '0'+(i%15);
send(client_sockfd, &buff, 1, 0);
}
client:
serv_addr.sun_family = AF_UNIX;
strcpy(serv_addr.sun_path, SOCK_PATH);
if((server_sockfd = socket(AF_UNIX, SOCK_STREAM, 0)) == -1)
{
perror("Error creating server socket");
exit(1);
}
if ((connect(server_sockfd, (struct sockaddr *)&serv_addr, sizeof(serv_addr.sun_family) + strlen(serv_addr.sun_path))) < 0) {
perror("client connect");
return 1;
}
while(recv(server_sockfd, &buff, 1, 0) > 0){
//printf("data : %s\n", buff);
send(server_sockfd, &buff, len, 0);
}