Does Cn1 support serial ports? - codenameone

I will need the ability to communicate with a device attached via USB that shows up as a serial port. Is this possible with cn1? I haven't seen any reference to it. Does the native java import javax.comm.*; work on all platforms?

No, comm isn't portable. You would be able to bundle it into the desktop port but you'd need a different implementation for everything else using the native interfaces.
Before we had builtin support for sockets Steve created a cn1lib for socket support which you can use as a reference to how one would implement streaming data over native interfaces

Related

how to use zerotier in socket programming?

I am trying to create a file sharing application in which socket programming is done through c language and GUI is done using java. I am connecting c and java using JNI(java native interface).
Now to install this appication in different systems and establish communication between these application I was thinking of using zerotier, but I am not sure how to use zerotier to do this work of file sharing.
ZeroTier provides a BSD-style socket layer via the SDK (libzt).
Documentation / Examples: docs.zerotier.com/sockets
Github Repo: zerotier/libzt.
Basically you'd just build the library into your application and call the special ZT sockets in the same way you'd call normal sockets.

Support for DatagramSocket (UDP)?

My app requires minimal support for DatagramSocket (i.e. UDP).
Specifically, I need new DatagramSocket(), send(DatagramPacket p) and receive(DatagramPacket p). I'd like to support both iOS and Android.
My app works in the simulator, but I found this in the documentation: "At this moment Codename One only supports TCP sockets."
Is this likely to change anytime soon? Or will I have to dive into native code to accomplish what I need?
If it works in the simulator I guess you used the java.net API's which aren't supported. You can read this to understand why some API's including the java.net API's aren't supported.
You can use native interfaces to wrap native socket implementations for portability currently there are two such cn1libs but they focus on TCP sockets:
https://github.com/shannah/CN1Sockets and https://github.com/shannah/cn1-websockets
You can write a similar API targeting Datagram. To learn more about native interfaces see https://www.codenameone.com/how-do-i---access-native-device-functionality-invoke-native-interfaces.html

iOS Sockets library listen support

I am finding some conflicting articles, some are old, about CN1 not having Sockets but I see the library com.codename1.io.Socket. I have seen some articles saying it works on Android as well but not iOS. I need the capability to listen on a socket on iOS and was hoping to use an internal library. The shannah/CN1Sockets project doesn't appear to support listening.
From 2014, https://www.codenameone.com/blog/sockets-multiline-trees.html , and lists non iOS support. Any update on this?
Codova/Phonegap does have a few libraries and someone implements Chrome's TCP/UDP API for it as well.
Server sockets are very problematic across platforms as the iOS implementation is radically different from the Android implementation and a bit challenging to implement using the listen paradigm.
It's probably possible to implement server sockets on iOS but because there wasn't much demand and this required some work we chose not to do it. It's also not very useful ans phones move around/change networks. You won't get a stable IP to work against anyway. A better way would be to initiate communication from the client and then communicate back. Notice you won't be able to use a server socket in a background process in iOS anyway as the process will be killed when sent to background!
The only Cordova implementation I found is this: https://github.com/MobileChromeApps/cordova-plugin-chrome-apps-sockets-tcpServer
You can probably use that with native interfaces or just use it as a baseline for a pull request to implement server sockets on iOS but again it's very unlikely that what you are trying to do with server sockets won't work due to iOS limitations.

connection between windows and Linux sockets in 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.

develop BLE peripheral using C on intel edison

I am trying to develop a bluetooth LE peripheral in intel-edison, by using C library. The device should be able to :
advertise (GAP)
accept connection (GAP)
support custom GATT service, simply read/write value of characteristic.
I try to use HCI and bluez to implement this. bluez-experiments, intel-edison-playground, which demonstrate how to advertise and scan, can be compiled and run on edison. BLE advertising and scanning do work.
But I have hard time to figure out how to accept connection and support GATT service. I try to search on goolge about the HCI document but have no luck. Can someone provide a snippet of code (c or pseudo or a description)?
Thank you so much!
Andrew
If you download the bluez source you'll find documentation on the hci protocol in /doc/mgmt-api.txt. I'm not using the hci interface myself, and I'm not sure if the developers intend for implementors to use this interface to implement peripherals, so I'm not sure how well this will work.
I went with the DBus API approach for my project, which is outlined in /doc/gatt-api.txt and /doc/advertising-api.txt. This approach involves writing a program which creates DBus objects which support specific org.bluez DBus interfaces (GattService1 which contains GattCharacteristic1 and GattDescriptor1) and the ObjectManager interface to expose everything to bluez. You then use LEAdvertisment1 to define what is advertised and register the advertisement using the LEAdvertisingManger1 interface on the adapter.
I used Qt to simplify the DBus communication parts.
The DBus API for BLE on bluez is still in heavy development, and not all features are supported (I still haven't found a way to start and stop advertising, for example). 5.31 contains a lot of added supported and some critical bug fixes for descriptors, but requires a newer kernel.

Resources