0

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()
Sir Rufo
  • 18,395
  • 2
  • 39
  • 73
totom
  • 21
  • 1

2 Answers2

0

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?

Matt Evans
  • 7,113
  • 7
  • 32
  • 64
  • Yes, No connection could be established because the target computer explicitly denied it 192.168.43.37:8080 and when im looking on my server(raspberry pi) i listen the 8080 port : – totom Apr 25 '19 at 08:32
  • And can you please tell me how i can check if the port 8080 is open on the remote machine ?? and how i can check the web service/API end point is available in a browser?? (I work on visual studio for the client and raspberry pi for the server ) – totom Apr 25 '19 at 10:13
0

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});`
`});`

});

totom
  • 21
  • 1