connection between windows and Linux sockets in c

4.3k Views Asked by At

I am using the socket module in python to send commands to my raspberry pi to turn GPIO pins on and of.

I am switching to C, where I will use winsock.h and winsock2.h to create the server on my PC and sys/socket.h to create a client on the raspberry pi.

Is it possible to establish a connection between these two different libraries?

I only want to create a socket, bind, send and recv. No other operations.

1

There are 1 best solutions below

0
Wambitz On

I recommend you to check this documentation, there are some examples for a Windows Server / Client connection:

https://learn.microsoft.com/en-us/windows/win32/winsock/getting-started-with-winsock

For Linux you need to do some adaptations as you might know or you have already implemented, I did the same for 2 desktop applications to send data from a Linux PC (client) to a Windows PC (server). As mentioned in the comments it doesn't matter the devices while they are in the same network and follow the TCP/IP protocol.

I was able to do this even connected through a VPN. Unfortunatelly I can not share the code. But I developed this communication based on the documentation from the link above.

I hope it helps. Actually if you want to use Python in the raspberry Pi there is also a python built-in package that you could use: https://docs.python.org/3/library/socket.html

And you can use the code from the link above in Windows. It should be straighforward.