0

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.

MD XF
  • 7,860
  • 7
  • 40
  • 71
Rose White
  • 21
  • 1
  • 6
  • 4
    the connection is not between the 2 libraries, it is between the 2 machines, and any library is fine. – bansi Mar 16 '17 at 12:13
  • 3
    It should not matter which library you use. Its the underlying protocol that matters. If you create a server socket using TCP protocol, then you should be able to connect to it from any client using any operating system and hardware using TCP protocol provided both the machines are on same network. – prashanthns Mar 16 '17 at 13:29
  • Have you tried it and failed? – Mad Physicist Mar 16 '17 at 17:39
  • i have not succeeded yet on making a `winsock.h` socket but the `sys/socket.h` on the raspberry pi worked and i was able to establish a connection between the socket and putty. – Rose White Mar 16 '17 at 19:33
  • update: again i have not succeeded yet on making a `winsock.h` socket but a connection between python `socket` and `sys/socke`t worked so i am sure what you guys said is right the library does not matter it only matters if i am using TCP or UDP – Rose White Mar 17 '17 at 10:41
  • A socket is an OS object. There are no winsock sockets different from python sockets different from tcl sockets different from..., they are all one and the same thing, you are just trying to use it through different wrappers. If you have a problem using winsock, ask a question about that problem. – n. m. could be an AI Mar 21 '17 at 17:54
  • @n.m. i trying to create a socket using `winsock.h` but the program is always giving socket error as an output as the if statement is executed here is my code https://gyazo.com/5247f07f226031cb5fb650c3ab629137 what is my mistake ? – Rose White Mar 21 '17 at 19:16
  • Please use [this link](http://stackoverflow.com/questions/ask) to ask a question. – n. m. could be an AI Mar 21 '17 at 19:38

1 Answers1

0

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.

Wambitz
  • 355
  • 1
  • 2
  • 13