Sockets can be multilanguage?

-1

Because sockets are a common choice for high-performance communication between cross-platform applications , my question is, does that also make them multilingual?

Bringing the situation to my context, what could be the reason why a server-side algorithm developed in C did not communicate with a client developed in another language?

Is there any specific configuration in the server algorithm so that it is able to recognize only client communication requests developed in the same language?

I developed the C server [in Linux] and the client is a serial redirector [in Windows].

I provide below the server algorithm I am using:

Server.c

  • The code has been tested and works with a client * (. c)

    int main(void)
    {
    
    int socket_serv, socket_cli; 
    struct sockaddr_in addr_server;
    
    //Cria o socket servidor
    socket_serv = socket(AF_INET, SOCK_STREAM, 0);
    setsockopt(socket_serv, SOL_SOCKET, SO_REUSEADDR, &(int){ 1 }, sizeof(int));
    
    if (socket_serv == -1)
    {
        perror ("Nao foi possivel criar o servidor!\n");
        return -1;
    }
    
    //Prepara a estrutura do endereco do socket servidor
    addr_server.sin_family = AF_INET;
    addr_server.sin_addr.s_addr = inet_addr("192.168.15.15");//INADDR_ANY;
    addr_server.sin_port = htons(2000);
    
    //Bind
    if (bind (socket_serv, (struct sockaddr *)&addr_server, sizeof(addr_server)) < 0)
    {
        perror ("Falhou o bind no servidor\n");
        return -2;
    }
    
    //Listen
    listen (socket_serv, 1);
    
    //Aceita uma conexão de um cliente
    puts ("Aguardando cliente...\n");
    while ( (socket_cli = accept (socket_serv, 0, 0)) )
    {
        puts ("Cliente conectado!\n");
        ....
    }
    
    return 0;}
    
asked by anonymous 08.11.2018 / 15:39

1 answer

2

Yes.

No matter what language an application that uses sockets is written to, at the end of the day, communication is performed by drivers at the operating system level.

This question does not even make sense.

UPDATE

This line

addr_server.sin_addr.s_addr = inet_addr("192.168.15.15");//INADDR_ANY;

could be problematic, because it is limiting bind only to a network interface ... the common thing is to use INADDR_ANY, which is commented out.

This line

while ( (socket_cli = accept (socket_serv, 0, 0)) )

is wrong because it is not detecting possible errors in accept. Although it is not common, errors in accept can happen (I've seen it happen). The correct one should be to test if the value of "socket_cli" is different from -1.

Without more information (for example, what error specifically happens?) it is difficult to have an idea of what is happening.

I suggest doing a trace with tcpdump or wireshark and see if you can get more information.

    
08.11.2018 / 15:52