简体   繁体   中英

Unable to connect Python Websocket server using Dart Client

Issue:

When I am trying to connect to server.py using client.py then it is working and I am getting the response like this在此处输入图像描述

But, when I am trying to connect to Python server using Dart then getting following error: 在此处输入图像描述

My server.py file content:

import socket

server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind(('192.168.0.102', 59000))
server.listen()
client, address = server.accept()
client.send('You are connected'.encode('utf-8'))

My client.py file content

import socket

client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client.connect(('192.168.0.102', 59000))
message = client.recv(1024).decode('utf-8')
print(message)

My dart client

import 'package:web_socket_channel/web_socket_channel.dart';

void main(List<String> arguments) {
  final channel = WebSocketChannel.connect(
    Uri.parse('ws://192.168.0.102:59000'),
  );
  channel.stream.listen(
    (data) {
      print(data);
    },
    onError: (error) {
      print('Error : $error');
    },
  );
}
import socket

server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.bind(('192.168.0.102', 59000))
server.listen()
client, address = server.accept()
client.send('You are connected'.encode('utf-8'))

This is not implementation of WebSocket server, as it is not compliant with RFC 6455 . If you want to use with WebSocket client, either alter your code that it is compliant with all normative parts of RFC 6455 xor use ready WebSocket server implementation provided by external package for example websocket-server but before using please comprehend its' documentation .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM