0

I see there are questions on how to send data form the RPi to the PC but I want to send data the other way around. I have a program in C++ that when I push a button I want it to light up an LED connected to my RPi. How is this possible and is it a two-way connection? Preferably I want to use the wifi connection too if that's possible.

  • 1
    Expanding on Golidlocks answer, it would be best to use a programming language to do this. Python is a good way to start on the Pi. But you need atleast two endpoints, the Pi and your other machine. Try using TCP stack with simple POST data form the Pi and the other machine will listen to POST's and do what ever it is needed. – Piotr Kula Feb 21 '15 at 0:34
7

From a programming perspective, messages on networks are transferred via sockets. There are two predominant forms of networking, connection (aka. stream) based and connectionless (aka. packet) based. The latter uses the UDP protocol and the former the TCP protocol. TCP connections are established between servers and clients; some applications maybe capable of either role, but when considering a connection and how to make a connection, one party is always the server and the other party is the client. A server is an application with a listening socket assigned to a specific port. When a client wishes to connect to the server, it uses the network address (e.g. 192.168.1.2) of the system where the server is running and the specific port number of the server itself. Various server applications may be running on one system, but they each have a unique port number. Once a TCP connection is established, it is assigned to a separate, arbitrary open port different than the server port, so the server port can continue to listen for new clients while the application exchanges messages with established clients.

UDP applications also use port numbers, but rather than client-server relations, they simply send and receive from the same port. No persistent connection between parties is established. This means no one has to wait around for anyone else, but it also makes it harder to guarantee a correct sequence of messages as they may become disordered travelling slightly different routes from one place to another.

There is nothing special about the pi in this regard, so further questions about network programming should go either to Stack Overflow, or, since the pi is usually linux based, Unix & Linux. However, I strongly suggest now you have a starting frame of reference that you do some research first, since there are literally tens of thousands of Q&As, tutorials, how-tos, forum threads, etc. on this topic and there is no need to regurgitate the basics again. Wikipedia is always a great place for sorting out various concepts.

  • Thanks, I realize my "noob" question got me a downvote but it's helpful folks like yourself that keep these communities running. +1 – Jacksonkr Feb 25 '15 at 1:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.