Can trigger.io open a TCP socket? - sockets

Is there an easy way to open a TCP socket to connect a TCP server? Should I use socketjs, jsocket or something else?
I try to develop a cross-platform application to connect to a TCP server and pull data from it.
Thanks

No, we do not have an API for that at present. But you can use WebSockets on iOS, and libraries like socket.io which fall back to long-polling on Android.
If you email us at support#trigger.io we can advise on your specific requirements and see if it could make sense to offer a native API.

I'm the author of trigger.io-tcp, an android-only trigger.io native module that allows you to open TCP sockets for sending/receiving data.
You can use it if you need sockets only for Android or fork it and write the iOS part.

Related

Connect to TCP server with WebGL Unity

I have a TCP server (which I can not change/modify) running which sends data and I want it to connect to Unity WebGL build.So first of all I know it is natively not supported to connect to a TCP server in WebGL. I searched for workarounds and tried the following : Use Websockify to enable connection from the TCP server to a WebSocket. I used the NativeWebsocket Library but it would not connect to the server unfortunately. I also read about these blogs :
How to let a Unity WebGL build connect to a local python server?
https://forum.unity.com/threads/webgl-tcp-client.738419/
But they didn't really help either. Has anyone tried this or knows how to make it work (if it is even possible :) )?
Thanks in advance
Unity3D uses the .NET C# libraries, so even though Unity doesn't explicitly provide a TCP library, you can still use .NET's TCP APIs. It's worth noting that not all platforms will support this, for example, WebGL doesn't support TCP communication.
See the example in .NET documentation for help on implementation: System.Net.Sockets TcpClient
For WebGL, it is impossible to use TCP communication, so you'll have to wrap the server in some kind of HTTP/Websockets transport - you cannot leave the server as is, it will not work because the protocol cannot be communicated with for security reasons.
If you have any question as to the specifics of implementation, feel free to ask in the comments - I don't have enough information to elaborate further on your specific application

Is it possible to connect between NetworkManager (HLAPI) in Unity3D and socket server?

I try to connect between NetworkManager (HLAPI) in Unity3D and Socket server.
I have already tried to connect two Unity applications using HLAPI or LLAPI. It works well. But HLAPI or LLAPI Unity client can't connect to Socket server (python).
I think that HLAPI or LLAPI supports to connect among Unity3D applications. Is it right?
Is it possible to connect between NetworkManager (HLAPI) in Unity3D
and socket server?
The short answer is No.
These are two different protocols.
I once tried it. It seems to connect secretly then immediately disconnect. I can't remember if I tried it with TCP or UDP but you can't just do that.
HLAPI or LLAPI are built on on top of the UDP protocol and possibly TCP too in newer Unity version. In order to connect to it with an application not made with Unity, you will have to reverse engineer the HLAPI or LLAPI protocol and understand how they both connect to each other(Handshake) then build a custom API for python using raw socket.
If you want to communicate between Unity and a program made with python, I suggest you use standard socket (TCP/UPD). This is more less hassle and will allow your app to work with any language that supports socket.

What's wrong with having plain old TCP / UDP sockets in browser's API

What's wrong with having plain old TCP / UDP sockets in browsers' API?
I know that there's such thing like WebSockets (that is built via TCP under-the-hood) but hey, what's wrong with plain sockets? Is it due some security issues? If so, how WebSockets help to prevent them?

Is it possible to use UDP with socket.io?

I have a game I am working on and I heard that UDP is superior for real-time games. I know that socket.io uses TCP and was wondering if there is some way to switch it to UDP. I tried looking it up but only found posts from around 2012 which said UDP is only experimental in browsers.
From a standard browser, it is not possible.
From a browser client, socket.io uses either the http or the webSocket transport. Both http and webSocket are TCP connections, not UDP connections. So the browser client socket.io does not use UDP - it uses TCP.
As best I know, there is no standard UDP support in browsers accessible from regular HTML page Javascript so you can't even really try to build your own layer that uses UDP.
Other references on the topic:
Why Can't I Send UDP Packets From a Browser
Reading from udp port in browser
Chrome Supports TCP and UDP Sockets
Write a chrome extension to support UDP in browser
How to send a UDP Packet with Web RTC - Javascript?
How to talk to UDP sockets with HTML5?
Reading from udp port in browser
UDP can be a desirable transport for some circumstances when you want the packet to be delivered as soon as possible, but if it can't be delivered immediately, then just drop it. This is sometimes useful in gaming or even video streaming where the next packet will just contain the next update so if the previous one didn't come through, then no big deal and you'd rather not have TCP try to retransmit the lost packet. But, browsers don't support using the UDP protocol from web page Javascript.
If you want to connect to a UDP device or server from a browser, you will have to use some sort of proxy so your browser code can talk to the proxy over TCP (either http or webSocket) and then the proxy can handle the actual UDP communication with the device.
It would be possible to use the socket.io library from node.js or some other non-browser platform and write your own UDP transport add-in for socket.io that is built on the native UDP support in your platform. I believe socket.io has a somewhat pluggable transport so you could try to make your own transport and then configure both client and server to use that transport. This is not possible from the browser (without a native code plug-in installed in the browser) because there's no underlying UDP support in the browser that you could build your transport on, but in non-browser environments like node.js, you could do that.
It might be a good idea to use webRTC in this case which is UDP in nature.
Although the question is already answered, I want to point out that there are ways to implement socket.io with UDP. For example dgram does exactly what you are looking for.
This is a tutorial for socket.io + UDP with dgram.
UPDATE:
Alexandre Lacheze developed a node.js package that brings UDP to browser. It also supports socket.io. So the answer is somehow obsolete now.
UPDATE 2:
It turn out it is just a simulated UDP. Not an actual UDP protocol running on browser.

Best practice for connecting to a TCP service with Play

I want to connect to a locally running TCP service from a web application I'm building using the Play framework and scala.
I'm not sure how to open this connection and send commands to it, should I be writing raw socket code? Also, how should I be managing the connection? Can I just open the connection once and send commands from each web request to it? What if the connection is closed or falls over?
Not sure Pay will be of much help here, most of its modules focus on HTTP communication. You should have a look at Akka-IO though.