Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with parsing WebSocket IPv6. #5326

Closed
MrSorcus opened this issue Nov 27, 2017 · 8 comments
Closed

Problem with parsing WebSocket IPv6. #5326

MrSorcus opened this issue Nov 27, 2017 · 8 comments

Comments

@MrSorcus
Copy link
Contributor

MrSorcus commented Nov 27, 2017

[root@server]/tmp# python --version
Python 2.7.5
[root@server]/tmp# /tmp/crystal-0.24.0-2/bin/crystal --version
Crystal 0.23.0+313 [ea4187c57] (2017-10-27)

LLVM: 3.9.1
Default target: x86_64-unknown-linux-gnu
Chromium
Version 62.0.3202.94 (Developer Build) (64-bit)
Firefox
57.0 (64-bit)

First problem. Crystal can't connect to IPv6 address. From client to server.

Server:

require "http"

module Network
	class WebSocket < HTTP::WebSocketHandler
		HANDLERS = [] of HTTP::Handler
		def initialize (@path : String, &@proc : HTTP::WebSocket, HTTP::Server::Context -> Nil)
			HANDLERS << self
		end

		def self.run (host : String = "::", port : Int32 = 3030)
			puts "Run server on ws://[#{host}]:#{port}"
			HTTP::Server.new(host, port, HANDLERS).listen
		end
	end
end

Network::WebSocket.new "/" do |socket|
	socket.send("Hello World!")
	socket.close
end

Network::WebSocket.run

Client:

require "http"

ws = HTTP::WebSocket.new(URI.parse("ws://[::]:3030"))

ws.close

Error - https://gist.github.com/MrSorcus/d84c2a048aa629f251df08ad2662d7b9
Without URI.parse doesn't work too.

Second error. (But i don't know where is the problem). (resolved)

Server:

require "http"

module Network
	class WebSocket < HTTP::WebSocketHandler
		HANDLERS = [] of HTTP::Handler
		def initialize (@path : String, &@proc : HTTP::WebSocket, HTTP::Server::Context -> Nil)
			HANDLERS << self
		end

		def self.run (host : String = "::", port : Int32 = 3030)
			puts "Run server on ws://[#{host}]:#{port}"
			HTTP::Server.new(host, port, HANDLERS).listen
		end
	end
end

Network::WebSocket.new "/" do |socket|
		socket.send("Hello From Binary!".to_slice)
end

Network::WebSocket.run
ws = new WebSocket("ws://[2a01:4f8:xx:xx::xx]:3030/")
ws.onmessage = (message) => {
	console.log(message.data)
}

Console.log show me ArrayBuffer(13) with byte length and without any payload.

But! Python client (https://github.com/websocket-client/websocket-client) works fine.

from websocket import create_connection
ws = create_connection("ws://[::]:3030")
print("Receiving...")
result =  ws.recv()
print("Received '%s'" % result)
ws.close()

Binary receiving doesn't work in chromium & firefox.

UPD: Problem with JS-client resolved. Look at here - https://stackoverflow.com/questions/47531467/why-js-client-doesnt-receive-binary-from-server/47532253#47532253

@faustinoaq
Copy link
Contributor

faustinoaq commented Nov 27, 2017

I can reproduce this, Do We use some kind of different format for IPv6?

@MrSorcus
Copy link
Contributor Author

Usually IPv6 address must be a string in square brackets, no?

@ysbaddaden
Copy link
Contributor

ysbaddaden commented Nov 27, 2017

The bug is that eventually Socket::Addrinfo is told to resolve [2a01:4f8::] with the square brackets, which obviously can't be resolved; they must be removed at some point.

EDIT: this should be fixed in URI since this is an issue with representing an IPv6 address in an URI.

@MrSorcus
Copy link
Contributor Author

Ok. But what about problem with js-client?

@straight-shoota
Copy link
Member

What about that? You mentioned Javascript in the headline but there is no description about that...

@RX14
Copy link
Member

RX14 commented Nov 27, 2017

@straight-shoota yes there is, at the bottom of the issue description.

Regardless, seperate issues should be seperate github issues. Your second issue seems like something to investigate on gitter/irc/mailinglists though, instead of a concrete issue for the issue tracker.

@straight-shoota
Copy link
Member

That last example is python...?

@MrSorcus
Copy link
Contributor Author

That last example is python...?

Yes. After first problem look at line "Second error. (But i don't know where is the problem).". Create separate issue?

Regardless, seperate issues should be seperate github issues. Your second issue seems like something to investigate on gitter/irc/mailinglists though, instead of a concrete issue for the issue tracker.

No answer in gitter. But ok, i will try again later.

@MrSorcus MrSorcus changed the title Problems with WebSocket (JavaScript, Crystal, Python) Problem with parsing WebSocket IPv6. Nov 29, 2017
@MrSorcus MrSorcus closed this as completed Jan 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants