-
Notifications
You must be signed in to change notification settings - Fork 20
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
Doesn't work if I create Http server on same host but with other port #34
Comments
Hmmm - do you have a minimal example to run? Sounds strange. |
Doesn't work import haxe.io.Bytes;
import hx.ws.Log;
import hx.ws.SocketImpl;
import hx.ws.Types.MessageType;
import hx.ws.WebSocket;
import hx.ws.WebSocketHandler;
import hx.ws.WebSocketServer;
import js.node.Http;
class Ws
{
static public function main()
{
#if js
untyped global.WebSocket = require("ws");
#end
var server:js.node.http.Server = Http.createServer();
server.listen(5000, "localhost", () -> {
trace("Http server created");
new Server();
new Client();
});
}
}
class Client {
public function new() {
Log.mask = Log.INFO | Log.DEBUG | Log.DATA;
var ws = new WebSocket("ws://localhost:5001");
ws.onopen = function() {
ws.send("alice string");
ws.send(Bytes.ofString("alice bytes"));
}
}
}
class Server {
public function new() {
Log.mask = Log.INFO | Log.DEBUG | Log.DATA;
var server = new WebSocketServer<Handler>("localhost", 5001, 10);
server.start();
}
}
class Handler extends WebSocketHandler {
public function new(s: SocketImpl) {
super(s);
onopen = function() {
trace(id + ". OPEN");
}
onclose = function() {
trace(id + ". CLOSE");
}
onmessage = function(message: MessageType) {
switch (message) {
case BytesMessage(content):
trace(content.readAllAvailableBytes());
case StrMessage(content):
var str = "echo: " + content;
trace(str);
send(str);
}
}
onerror = function(error) {
trace(id + ". ERROR: " + error);
}
}
} Works import haxe.io.Bytes;
import hx.ws.Log;
import hx.ws.SocketImpl;
import hx.ws.Types.MessageType;
import hx.ws.WebSocket;
import hx.ws.WebSocketHandler;
import hx.ws.WebSocketServer;
import js.node.Http;
class Ws
{
static public function main()
{
#if js
untyped global.WebSocket = require("ws");
#end
var server:js.node.http.Server = Http.createServer();
new Server();
new Client();
server.listen(5000, "localhost", () -> {
trace("Http server created");
});
}
}
class Client {
public function new() {
Log.mask = Log.INFO | Log.DEBUG | Log.DATA;
var ws = new WebSocket("ws://localhost:5001");
ws.onopen = function() {
ws.send("alice string");
ws.send(Bytes.ofString("alice bytes"));
}
}
}
class Server {
public function new() {
Log.mask = Log.INFO | Log.DEBUG | Log.DATA;
var server = new WebSocketServer<Handler>("localhost", 5001, 10);
server.start();
}
}
class Handler extends WebSocketHandler {
public function new(s: SocketImpl) {
super(s);
onopen = function() {
trace(id + ". OPEN");
}
onclose = function() {
trace(id + ". CLOSE");
}
onmessage = function(message: MessageType) {
switch (message) {
case BytesMessage(content):
trace(content.readAllAvailableBytes());
case StrMessage(content):
var str = "echo: " + content;
trace(str);
send(str);
}
}
onerror = function(error) {
trace(id + ". ERROR: " + error);
}
}
} Build command
Run command
|
So i wonder if a better |
Ok. But the topic of question is another :) |
Oh, sorry, got mixed up! |
Issue is in MainLoop for NodeJS target in this case. |
Howerver works if I create websocket server before creating http server.
The text was updated successfully, but these errors were encountered: