Can sockets be multilingual?

Asked

Viewed 88 times

1

Since sockets are a common choice for high-performance communication between applications of different platforms, my doubt is, that makes them also multilingual?

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

There is, in this case, some specific configuration in the server algorithm so that it is able to recognize only communication requests from clients developed in the same language?

I developed the C server [on Linux] and the client is a serial redirector [on 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;}
    

1 answer

3


Yes.

No matter in which language an application that uses sockets is written, at the end of the day communication is done by drivers at the OS level.

This question doesn’t even make much 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 the bind only to a network interface...the common is to use INADDR_ANY, which is commented.

This line

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

is wrong because it is not detecting possible Accept errors. Although it is not common, Accept errors can happen (I’ve seen them happen). The correct should be to test whether the value of "socket_cli" is different from -1.

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

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

  • I appreciate the reply @zentrunix. Would you be kind enough to try to explain to me why my server program is not able to recognize the client I am using but a client developed in the same language? Any suggestions? Thank you!

  • 1

    Why your client is probably not communicating properly in another language. A more appropriate question than the one you asked could be: "why is this socket client in X language can’t communicate with this other server in Y language" - and the code of both, of course (a minimum code that would only show the connection to who will answer find the error). I agree that 'knowing that it is possible' is a prerequisite for this other question - so I suggest accepting this answer, and creating another more complete question

  • 1

    Caio de Paula Silva: as my colleague @jsbueno said, create a small test client program, and if you have problems post here the source of the client and the problem that occurred

  • I appreciate it. Too bad I don’t have access to the serial redirector code I’m using as a client... It intrigues me because he has served me with another server. But not this.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.