簡體   English   中英

與websocket服務器和客戶端的連接問題

[英]Problem connection with a websocket server and client

我在使用websockets的python編碼服務器和使用websockets的客戶端之間存在連接問題。

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

當程序生成時,它向我顯示

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()

我的法語生銹了,但我很確定異常轉換為目標機器主動拒絕連接。

我認為您的代碼沒有任何問題。

檢查遠程計算機上的端口8080是否已打開檢查Web服務/ API端點是否在瀏覽器中可用。

這篇文章包含了許多其他可能的檢查方法: 由於目標機器主動拒絕,因此無法建立連接?

var http = require('http').createServer(handler);

var fs = require('fs');

var io = require('socket.io')(http);

console.log('Server lauching'); http.listen(8080); //收聽端口8080

function handler (req, res) { //create server

fs.readFile(__dirname+'/index.html', function(err, data) { //讀取文件夾中的相應文件

if (err) {

res.writeHead(404, {'Content-Type': 'text/html'}); //出錯時顯示404

return res.end("404 Not Found");

}

res.writeHead(200, {'Content-Type': 'text/html'}); //寫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});`
`});`

});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM