Testing feathers socket - sockets

I have hardly done anything with feathers sockets so far and therefore I need your help.
I have written a test which tests the functionality of my websocket to move users into the right channels. To do this I created two socketIo-clients in my test and let them connect to the websocket with the help of my own helpers, which also do the authentication when the connection is established.
If I run the test on its own, it will work fine. But once I run all the tests together, the test no longer works, because the SocketIo-Clients can not established any connection. This can be noticed, because no connection event is triggered at the server.
In my Test I do:
before((done) => {
server = app.listen(app.get('port'), done);
socketUrl = 'ws://localhost:5555}/';
});
socket = io(socketUrl);
and
after(async () => {
await server.close();
});
I found out, that any test, which is also doing server = app.listen(app.get('port'), done); before the socket test, will cause the socket test to fail. Can it be possible, that await server.close(); does not really close the http-server and/or the ws-server?

Related

Flutter Socket.IO cannot connect to server, but browser works fine

Was going to use Socket.IO for authorizing in a flutter application, but it wont work on anything other than localhost:
String serverURL = "https://example.awsapprunner.com";
IO.Socket socket = IO.io('$serverURL/client', <String, dynamic>{'transports': ['websocket']});
checkUserExists(String phoneNum, context) {
socket.connect();
socket.emit('login', phoneNum);
socket.on('login_error', (res)=> {
log("new user"),
});
socket.on('session-started',(sid)=>{
log("old user!"),
});
}
The app won't even connect to the socket so anything after socket.connent() never runs.
Here's what I have tried
'autoConnect': true
replacing 'https' with 'wss' or 'ws'
removing 'https://' altogether
Different Cloud Services (AWS, GC, Azure)
local server (works and connects perfectly fine)
connecting to the server via browser (also works perfectly fine)

Create connected and disconnected callback for a binding socket using C#?

I have this binding socket:
Socket mainSocket = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.IP);
mainSocket.Bind(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 0));
And I need to know when an extern client is connected and disconnected from my servicies( ftp, database server, app server, etc).
thank for advance.
What I have tried:
I tried with these methods but, did not work for me.
mainSocket.BeginConnect(new IPEndPoint(IPAddress.Parse("127.0.0.1"), 0), new AsyncCallback(ClientConnected), null);
mainSocket.BeginDisconnect(true, new AsyncCallback(ClientDisconnected), null);
private void ClientDisconnected(IAsyncResult ar)
{
// here get some client info like Ip
}
private void ClientConnected(IAsyncResult ar)
{
// here get some client info like Ip
}
I need some help please. Thanks.
BeginConnect() and BeginDisconnect() are asynchronous operations. They are not events you can subscribe to.
BeginConnect() is for a client socket to asynchronously open a new connection to a server. BeginDisconnect() asynchronously closes an open socket.
To detect clients connecting to your server, you need to use Accept(), BeginAccept()/EndAccept(), or AcceptAsync() to accept inbound connections coming into your server socket. You will be given a new Socket for each accepted client to use for communicating with them.
There is no event for a client disconnecting from a server. If a client disconnects, pending/subsequent send/receive operations involving that client will fail. You need to handle those failures when they occur. For instance, if a client disconnects gracefully, a read operation from the client will end as successful with 0 bytes reported. But if the client disconnects abnormally, a read operation will end as failed with an error code reported.

Is it possible to send messages over UDP/TCP from flutter application to .NET application?

I am trying to figure out how to send data over UDP/TCP from my flutter application to my server which has .net applications which listen for UDP and TCP . I searched about it and I found that there is a package named web_socket_channel and I tried that it is working with the testing server ws://echo.websocket.org but when I replace the echo.websocket.org with my server IP address or domain name it doesn't work even i am not getting any errors back so I couldn't figure out what's going on. Is there something wrong? or am i doing something wrong? Can someone help me with my demo code :
WebSocketChannel channel;
String text = "";
void sendSocket() {
String message = "message_text"
if(message.isNotEmpty)
channel.sink.add(message);
}
getStreamData() {
channel.stream.asBroadcastStream().listen((event) {
if (event != null)
print(event);
});
}
#override
void dispose() {
channel.sink.close();
super.dispose();
}
#override
void initState() {
try {
channel = IOWebSocketChannel.connect(
'ws://127.0.0.1:8889');
getStreamData();
super.initState();
} catch (e) {
print(e.toString());
}
}
I appreciate your help. Thanks you so much.
First, make sure that your server is running and available to connect.
For this problem go through all steps mentioned below:
1. Check your server is running and the app is listening to a specific port on which you are sending data
2. Check the server IP address and Port number
3. Make ping from the command prompt using "ping serverName/IP"
4. Make sure you can connect using telnet from command prompt "telnet serverName/IP portNumber"
(if telnet command doesn't work means your telnet client is not installed/enabled then
check how to enable telnetClient)
1st Solution
if everything works well then try this plugin flutter_socket_plugin or you can write your own code for socket like #Richard Heap suggested.
2nd Solution
Excellent blog on Network Socket Programming for dart: Reference Link
You can also use RawDataGramSocket for the UDP sockets refer to this thread
Socket API for TCP sockets visit this thread

How to use node.js Context.IO behind a department proxy?

Here is my node.js code to use Context.IO in a RESTful way rather than IMAP.
var ContextIO = require('contextio');
var ctxioClient = new ContextIO.Client({
key: 'MY_KEY',
secret: 'MY SECRET'
});
ctxioClient.accounts().get(function(err, res) {
if (err) throw err;
console.log(res);
});
When I executed the above code on my dormitory computer, everything worked fine. However, when I executed the code on my office computer, which is behind a departmental proxy, the code simply timed out. My department provides both http and socks proxies for internet access. The question is how to set it up in node.js?
By the way, I also tried
socksify node code.js
It did not time out. Instead, it just did not response.

Can I set up socket.io chat on heroku?

I have a simple socket.io chat application which I've uploaded to one of the new Heroku 'cedar' stacks.
Now I almost have everything working but I've hit one stumbling block. On my localhost, I open a connection to the socket server from the client with:
// lots of HTML omitted
socket = new io.Socket('localhost', {port: 8888});
But on Heroku, I obviously must substitute something else in for these values.
I can get the port from the process object on the server like so:
port = process.env.PORT || 8888
and pass that to the view.
But what do I substitute for 'localhost'?
The correct way according the article on heroku is:
io.configure(function () {
io.set("transports", ["xhr-polling"]);
io.set("polling duration", 10);
});
socket = new io.Socket();
This ensures that io.Socket won't try to use WebSockets.
I was able to get Socket.IO v0.8 to work on Heroku Cedar by doing the following:
Within the Express app (in CoffeeScript in my case):
app = express.createServer();
socket = require("socket.io")
...
io = socket.listen(app);
io.configure () ->
io.set("transports", ["xhr-polling"])
io.set("polling duration", 10)
io.sockets.on('connection', (socket) ->
socket.on('myaction', (data) ->
...
socket.emit('result', {myData: data})
### The port setting is needed by Heroku or your app won't start
port = process.env.PORT || 3000;
app.listen(port);
And within the front-facing Javascript of your application:
var socket = io.connect(window.location.hostname);
function sendSocketRequest() {
socket.emit('myaction', $("#some_field").val());
}
socket.on('result', function(data) {
console.log(data);
}
Helpful links:
Heroku Node help
Heroku Socket.IO help
This has now changed as of Oct 2013, heroku have added websocket support:
https://devcenter.heroku.com/articles/node-websockets
Use:
heroku labs:enable websockets
To enable websockets and dont forget to remove:
io.configure(function () {
io.set("transports", ["xhr-polling"]);
io.set("polling duration", 10);
});
After trying every combination under the sun I finally just left it blank. Lo and behold that works perfectly. You don't even need the port.
socket = new io.Socket();
I was also having this problem on heroku. I was able to make it work using the hostname "myapp.herokuapp.com" (or simply window.location.hostname, to work both local and in production) and setting the port to 80. I'm using SocketIO 0.6.0.
Wouldn't you just put your actual hostname?
2011-06-25T21:41:31+00:00 heroku[router]: Error H13 (Connection closed without response) -> GET appxxxx.herokuapp.com/socket.io/1/websocket/4fd434d5caad5028b1af690599f4ca8e dyno=web.1 queue= wait= service= status=503 bytes=
Does this maybe mean the heroku router infront of the app is not configured to handle web socket traffic?
[update]
It would appear as of 6/22/2011 the answer is yes... heroku does not support socket.io see this post: http://blog.heroku.com/archives/2011/6/22/the_new_heroku_2_node_js_new_http_routing_capabilities/