How to check coap connection status and stop coap server in Coap Simple Library - arduino-esp32

I have a coap server running over an ESP32 by using Coap Simple Library.
Inside the loop function, I want to check if coap is connected and if it is stop it.
This is my code.
Methods bool conneted() and disconnected() or stop don't work.
if( coap.connected() ){
coap.disconnect(); // or coap.stop()
}

Do you refer to coap-simple.h, I can't find "connected" nor "disconnect".
If CoAP over UDP (RFC7252) is used, "connected" or "disconnect" doesn't have the same meaning as for TCP. Using UDP there is no connection and the messages are exchanged spontaneous. Using "connect" on UDP then mainly means, that the socket only accepts messages from that peer and not also from others. I don't think, that's what you want.
So, if your concern is, that a server may collapse because of too many "connections", the very good news is: no a UDP server doesn't. Therefore no "connect", no "disconnect".
The open question maybe, why there is no "stop", but that's a question for the CoAP-simple-library project.

Related

Parralel websocket connections. Imitating UDP

I'm building a fast paced webgl game and as a common problem I'm experiencing is the retransmits of lost TCP(websockets) packets on higher packet send / receive frequency.
Two options I considered:
1. using webrtc with node.js client to simulate node.js as a peer and connect it to browser for UDP use. So far unsuccessful to connect it to heroku, though works great locally. Is this possible, are there any limitations I overlooked which made it impossible for me to implement into heroku?
2. using multiple websocket connections from single client to a single user on server. Server & client would discard those messages that come from an older tcp packet (let's say 30-60ms delay due to retrasmits). Therefore making it seems like it's a UDP connection. Is this valid, would those connections break each other or work independantly, are there other really bad drawbacks to this method ? This would be an easier alternative to implement.
The reason I would not like to connect two clients via webrtc, but rather need it to connect to server is security. Thanks in advance.

How can i drop or ignore "syn" packets for opening connection in perl socket programing over linux that use listen() function?

I need a way to ignore connection requests (e.g syn req) for my server that listens via "listen()" funcion using perl socket programing.
I realized that "listen()" listens to the socket and response imidiately to syn request with syn-ack.
delay the syn-ack response to the request is also countable.
Thanks !
I don't think this is as easy as you think, because the listen() function works at a higher level than the TCP/IP packet stream. It opens a socket, tells the OS to accept incoming connections.
It's therefore the OS that's handling the SYN packets first, and is why firewalls are often used to deal with this problem. You might be able to do something involving generating your own packets (I haven't tried, so I'm not going to recommend anything) and manually 'handling' the connection. (You'd almost certainly need to be operating as a privileged user to do this too).
But I would have to ask - why do you want to do this?
I mean SYN is an essential part of the 3-way handshake of setting up a TCP/IP session. If you don't want a TCP/IP session to be established, then why open a port in the first place?
I would suggest that if it's for filtering of incoming traffic, then the tool for the job is a firewall like iptables.

Session start request using UDP sockets

I have been using UDP sockets to send and receive voice through RTP packetization. It is pretty straightforward. I just send my mic voice signals ( that are encoded ) over IP using User Datagram socket , and on the other end i receive the UDP-RTP packets and decode them to be able to play them on my speakers.
I have been searching on internet for a while to find a way to start up a session using UDP sockets. What i want to to is to a Handshake-like process between two ends of my conversation and after the requests were acknowledged the media layer ( which i described in first paragraph ) would fire and start sending voice.
I have not been able to find any tutorials on session request using UDP sockets but i suppose it shouldnt be impossible.( one user sends a request to build a session and if the other user confirms media layer starts)
Has anyone done something like this before? any info is welcome.
Firstly, UDP is a connectionless, unreliable protocol, you won't find anything like handshaking for negotiating connection i.e no session management. But, to transport RTP packets it's not a good idea to use tcp, it lacks realtime feature, so you have to stick with UDP. Now, to overcome the signaling problem you can use protocols like. SIP. It's standard signaling protocol used in VOIP. SIP initiates a connection before sending RTP packets. To properly use SIP and RTP you might have to take help of another protocol called SDP, which tells which port to use for transmitting RTP and other various info. You can get more info about these techniques here. Hope this will helps!

Can the same socket.io interface support traditional socket connection as well as websocket connection

I have to support a GPS devices that writes to a socket and at the same time websockets from suppose a mobile device. Can the same socket.io code support both of these?
Short answer : no such module for socket.io to call or serve TCP requests doesn't exist .
Long answer : you can easily solve this in your node.js by working with this possible options
First option would be to just support socket.io all the way client
and server. So you can easily develop with one protocol.
Second option is to combine socket.io + TCP server, and handle
received requests with the same handler. To simplify take this as an
example for server-side.
// run socket.io server
// run TCP server
function Handler(event,data,socket){
this.getProfileData=function(data,socket){
// things to do
// call socket.emit for socket.io ,or socket.write for TCP
}
this[event](data,socket); // call appropriate event
}
// when receiving a new message from either socket.io or TCP
new Handler(event,data,socket);
Third option is to use a bridge such as WebTCP or implement your own bridge.
There is also experimental TCP socket API for browsers, but its not recommended.

How do you emit to a room using Socket IO over UDP/Dgram?

Emitting to rooms is pretty straight forward. How do you emit to a room using Socket IO over UDP/Dgram? Or is this not possible currently. Not talking about browser usage. Server Only.
Socket IO Room Emitting
https://github.com/LearnBoost/socket.io/wiki/Rooms
NodeJS Dgram UDP Example
http://nodejs.org/api/dgram.html
Can they work together? Or is there a workaround?
Um, I'm pretty sure socket.io is TCP-based which means you cannot send UDP datagrams and expect them to be received by a socket.io server.
From The WebSocket Protocol:
The WebSocket Protocol enables two-way communication between a client running untrusted code in a controlled environment to a remote host that has opted-in to communications from that code. The security model used for this is the origin-based security model commonly used by web browsers. The protocol consists of an opening handshake followed by basic message framing, layered over TCP.

Resources