iOS Sockets library listen support - codenameone

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.

Related

Stomp protocol in Codename One

I don’t feel comfortable using WebSocket with Codename One and Spring Boot. Maybe my “error” was the implementation of one my own communication protocol over websocket, featuring ack and other hard to implements things. My protocol have issues that I wasn’t able to fix... I spent a lot of time creating it, but there are too much complexities for me.
Today I discovered that I tried to reinvent the wheel... since there are protocols over websocket like STUMP:
https://www.toptal.com/java/stomp-spring-boot-websocket
STOMP is a simple text-based messaging protocol that was initially created for scripting languages such as Ruby, Python, and Perl to connect to enterprise message brokers. Thanks to STOMP, clients and brokers developed in different languages can send and receive messages to and from each other. The WebSocket protocol is sometimes called TCP for Web. Analogically, STOMP is called HTTP for Web. It defines a handful of frame types that are mapped onto WebSockets frames, e.g., CONNECT, SUBSCRIBE, UNSUBSCRIBE, ACK, or SEND. On one hand, these commands are very handy to manage communication while, on the other, they allow us to implement solutions with more sophisticated features like message acknowledgment.
Is there any Stomp implementation for Codename One? Or the implementation of any other protocol over websocket? Thank you
I'm afraid not at this time. I also tried looking for implementations in Java but couldn't find any. It would actually be really nice if we had something like that.
I found an implementation for Android but I didn't get the chance to look at the complexity of porting it to Codename One.

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

Does Cn1 support serial ports?

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

BlackBerry OS 5 - 7, how to implement listener to listen if BlackBerry Device just get internet connection

I have questions about programming in BlackBerry Devices OS 5 - 7. Is there a listener that can listen if the device is just connected to internet connection? The task of my app is that if the device is connected, it will send a http request right away.
Looking forward to it.
Best regards,
Hammy
The listener you want is called CoverageStatusListener. Have a look at the API: CoverageStatusListener and CoverageStatusListener OS6.0+. Note the two flavours - you might want to use the extended version in your OS 6 and above apps.
But that said, coverage is only 1/2 the story. You might have good coverage but no access to the specific web site you are targeting. Another common problem is things like WiFi Hotspots - you can be talking quite happily on WiFi, but unless you have signed in to the Hotspot, you are not going to be able to communicate with your web site. So the many links that have already been provided by Signare (in the comments for your question), are useful. Here they are again, plus one more that I think is useful:
how-to-check-availability-of-internet-connectionwifi-gprs-edge-in-blackberry
how-to-check-for-an-active-internet-connection-in-blackberry-sdk
how-to-check-internet-connection-in-java-in-blackberry
how-to-check-network-connection-type-in-blackberry

Is there any framework to allow P2P communication via phone?

I want to build an app that allow P2P communication(send message, exchange files), I build the app with phonegap, since I want my app cross platform.
I know WebRTC allow real-time communication, but browsers doesn't support it very well. I also found Websocket plugin for phonegap, this satisfied part of my requirement, I can use this send message, but if I use websocket to send files from A to B, I guess all traffic will go through my server, it a pressure for server and I don't want my server carry so much traffic. I can't make a peer to peer connection between A and B.
Is there anyway to make a P2P communication on phone? Any workaround solution is also welcome.
You can do peer to peer connections using Flash or the recent WebRTC. Currently these are the only options you can use to do so, as WebSockets will only connect to a server.
As Flash is not supported by most phones (only Android < 4.0 has support), you can only use WebRTC. But WebRTC is only available on Chrome Beta for now, so you'll still have a cross platform app that will not work in most platforms/devices.
You will have to go through server (WebSockets or HTTP) to increase the number of devices you can cover.
You can use Boost asio sockets to build you own P2P app. but you need to build it for Android NDK and IOS.
Please do take a look at these links before you get into a conclusion
Official "Boost library" Support for Android and iOS?
Limitations to using (Boost) Asio with Android NDK
http://beta.boost.org/development/tests/trunk/developer/summary.html
http://www.codeproject.com/Tips/555070/Boost-vs-OSX-iOS-XCode
Hope it helps
On WebRTC you can use RTCDataChannel, in my experience, on chrome, using this involves writing a lot of code around reliability as the packets arrive out of order or not at all if sent too quickly.
However I think as the WebRTC spec evolves this will improve with implementation.
Use this for generating a RTCDataChannel enabled peerconnection:
var localpeer = new webkitRTCPeerConnection(localConfig,{ 'optional': [{'RtpDataChannels': true }] });

Resources