I have a connection problem between a python-encoded server that works with websockets and a client that works with websockets too.
using System;
using System.Collections.Generic;
using System.Linq; using System.Text;
using System.Threading.Tasks;
using WebSocketSharp;
namespace test1 {
class Program {
static void Main(string[] args)
{
using (var ws = new WebSocket("ws://192.168.43.37:8080"))
{
ws.Connect();
Console.ReadKey(true);
}
}
When the program is generated it shows me that
25/04/2019 09:48:31|Fatal|WebSocket.Connect|System.Net.Sockets.SocketException (0x80004005): Aucune connexion n'a pu être établie car l'ordinateur cible l'a expressément refusée 192.168.43.37:8080 à System.Net.Sockets.TcpClient..ctor(String hostname, Int32 port) à WebSocketSharp.WebSocket.setClientStream() à WebSocketSharp.WebSocket.doHandshake() à WebSocketSharp.WebSocket.connect()
My French is rusty, but I'm pretty sure that exception translates to the target machine actively refused the connection.
I don't think there's anything wrong with your code.
Check that port 8080 is open on the remote machine Check that the web service / API end point is available in a browser.
This post contains a number of other possibilities to check: No connection could be made because the target machine actively refused it?
var http = require('http').createServer(handler);
var fs = require('fs');
var io = require('socket.io')(http);
console.log('Server lauching');
http.listen(8080);
//Listen on port 8080
function handler (req, res) { //create server
fs.readFile(__dirname+'/index.html', function(err, data) {
//read corresponding file in folder
if (err) {
res.writeHead(404, {'Content-Type': 'text/html'});
//display 404 on error
return res.end("404 Not Found");
}
res.writeHead(200, {'Content-Type': 'text/html'});
//write HTML
res.write(data);
return res.end();
});
}
io.sockets.on('connection', function (socket) {
`socket.on('config', function (data){` //When the webserver receives a websocket in channel 'config', logs the data and send a response to confirm for the user
`console.log("data received");`
`console.log(data);`
`socket.emit('config', {'received':true});`
`});`
});
User contributions licensed under CC BY-SA 3.0