connection between windows and Linux sockets in c - c

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.

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.

Related

File access between mcu and PC through rs232 communication

I'm using a LPC178 development board and I want to read a file present on a Windows PC. My dev board only has a RS2323 interface to communicate with.
How can I go about transferring the file from my PC to my MCU using a RS232 (serial) link? I found a reference which explains how to transfer data between a MCU and PC but it isn't about file transfers.
Afaik there is no easy solution for this like calling something like "copy" or "fopen" over RS232. I would be happy to be proven wrong here.
The fastest solution might be to write a little programm running on your Windows Host, which listens to your RS232 communication and pipes your communication into/out of the file based on your communication protocol. This can be done with standard file operations in the language of your choice, for example C, C++ or Python.
Your problem is one of the oldest in the book. How do you transfer files without fancy operating system abstractions. For RS232 (or any other serial method) there exists many file transfer protocols.
One of them is kermit. This is a protocol from 1981 and can transfer binary and text files. It is able to be embedded in a micrcontroller and there exists programs to transfer/receive using kermit.
alternative old site for reference
In the simplest case you would use a file transfer protocol such as XMODEM, YMODEM, ZMODEM or Kermit - these protocols were designed in the days before networking and the Internet were ubiquitous and deal with simple point-to-point transfers between two computers. They are supported bu most terminal emulator tools such as TeraTerm Pro or PuTTY so no specific PC software need be written, just the microcontroller end.
A more complex but flexible solution is to implement a TCP/IP stack and a PPP driver, and an FTP application layer - probabaly only practical if using a third-party TCP/IP stack and application layer. You can then use any FTP client for the PC end, so again no PC software required. While this may be overkill if all you need to do is transfer files, it has the advantage of allowing you to use the the single serial port concurrently for other data streams and application protocols such as Telnet. The disadvantage perhaps is that while Windows does support PPP it is buried within the dial-up networking and to be frank a pain to get working.
Very first step you have to do is ensure serial communication is working fine.
Send a byte continuously from mcu to PC and display it on some io console (for example: HyperTerminal, Dock light )
Receive a byte to mcu from PC and echo it back to PC.
Once you are sure that serial communication is working fine then select some file transfer protocol and implement it.
While you can select any of the available protocols or write your own protocol and implement it.
For purpose of discussion i select Xmodem protocol.
If you consider some other protocol you may stop reading answer here.
XMODEM is a simple file transfer protocol.
Refer http://web.mit.edu/6.115/www/amulet/xmodem.htm for detailed information.
You may implement Xmodem mcu side by reading protocol. Or may consider using open source also ( if available )
PC side i prefer to use HyperTerminal io console as it is compatible with Xmodem.
In HyperTerminal all that i have to do is configure settings and select file for transfer to mcu.
Now transfer any file to mcu using Xmodem protocol from PC.
What you do with received file in mcu is up to you : )

Is it possible to open a C socket to an internet address through bluetooth

I am asked to connect my device to a server via a bluetooth connexion, such as an android tablet that gives an internet access via bluetooth.
The software on my device is entirely C, and the device runs a debian.
I know how to use regular network sockets, and how to use bluetooth sockets, which is practically the same.
but I have strictly no idea how I could use some sort of bluetooth gateway to access the internet, IE what if I want to write on a socket that's open with a distant server over the internet... through a bluetooth socket? As far as I'm concerned, the bluetooth sockets I open are strictly reserved to the machine I am in direct connexion with.
An application on the side of the android/ios device is apparently out of question.
Is this actually possible, and if yes, where should I look?

Getting MAC adds of machine in C with MacOS

I am dealing with socket programming with C language and Xcode. I can open socket, server and client. I need to learn my machine's Mac address and then, I will send Arp request for server machine.
Almost all examples had been written for linux. I need to solve it in Mac OS.
Currently, I am using these codes with opening two projects and they are able to communicate.
https://www.geeksforgeeks.org/socket-programming-cc/
Could you give some example or information about this problem?

establish bluetooth piconet connection between server and two clients using c on linux platform?

I want to establish Bluetooth network where one server can communicate to two clients (ie piconet) using C programm on linux platform, rfcomm based communication.
Can any one please share your guidance or sample source code if have.
I newbie to the bluetooth technology, have not found any useful info or code from internet source so far. so please.
Thank you
Basu
Linux runs open source BlueZ Bluetooth Stack, which works quite well (unless you need Bluetooth Low Energy). You can check out this tutorial: http://people.csail.mit.edu/albert/bluez-intro/c404.html
PS. Mind the GPL license when using #include like in those examples.
Edit:
As for creating piconet specifically, I'm afraid I don't have any snippets. However, after quick search, I would look into using bluez library to open not one but many RFCOMM sockets. So you can listen to and accept multiple connections.

l2cap server/client using IOBluetooth (osx bluetooth stack)

I'm having trouble understanding the API to set up a l2cap (or RFCOMM) client/server running on OSX like I can with BlueZ on Linux.
On Linux, I simply open a socket, bind, listen & then accept for the server, & socket, bind, connect for the client (w/ the bind taking in the BT address of the device I want to use). Also, there's no pairing done.
I can't figure out how to configure my application to start listening for connections on a particular device (or if OSX only supports 1 BT adapater at a time, then how to listen for any incoming connections).
I also can't figure out how to configure my application to send to one BT device using a particular device (this is irrelevant if OSX only supports 1 at a time).
Also, does the OSX stack require pairing to have occured between 2 devices before it'll pass through l2cap?
Any language examples would be appreciated, although C/C++ would be preferred.
Thanks
In Mac OS X 10.5 there's an example (in /Developer/Examples/Bluetooth, titled RFCOMM_Open_SPP_Example) that shows connecting to and reading data from a bluetooth device (i've used it to read NMEA lines from a BT GPS receiver). See also: Leopard & Bluetooth RFCOMM channels
Unfortunately I can't find a copy of the example project anywhere.
It looks like the code samples have been replaced with: Developing Bluetooth Applications

Resources