I'have created websocket like this:
Create "Hello World" WebSocket example
I have a problem because server doesn't send message to Client and in JS script function onmessage() is never fired. The connection is closed right after second send() on server is fired or after while. Do you know how to fix it? There is no respectable documentation for websockets and I couldn't find right answer why it doesn't work. Thanks for all answers.
#edit
There is an error after sending second message.
An error: An established connection was aborted by the software in your host.
There is also an error in javascript. When the second message is sending I get an error: Invalid frame header.
I have no idea why the first message with header works but the second with data doesn't.
I solved it. When u use socket server and websocket client you have to create your own frame for sending data back to client and it works fine.
Related
Why does my WebSocket connection always closes with 1006 error code, even when I use .close(1000) or .close(3000).
Interestingly, when using the WebSockets connection with Express.js and Express-ws, this does not happen, only when using our real API. Could it be something the server does? Isn't 1006 local only though?
Any help would be appreciated.
Thanks
This answer says:
Close Code 1006 is a special code that means the connection was closed abnormally (locally) by the browser implementation.
If your browser client reports close code 1006, then you should be looking at the websocket.onerror(evt) event for details.
...
I'm making a remote debugging tool for Unity(C#), and I've set up a C# WebSocket server in the game that emits Log messages.
The remote debugging client is in JavaScript, on a page served by an http server also created by the game.
I seem to be running into issues sending messages on some browsers, and I'm not sure why. I am running the websocket server on localhost and running the client locally, and I know that kind of stuff is not really liked by chrome/firefox. But the weird thing is that I'm not getting any hard errors or exceptions. Failures seem to fail silently.
I'm pretty certain that the issue is JS/Browser related as the C# websocket server works and receives connections in all cases.
Anyway, here's the socket part of the JS code:
var socket = null;
var host = "ws://"+window.location.hostname;
var port = 55000;
var url = host+":"+port+"/msg";
function CheckSocketStatus()
{
if(socket!=null){
console.log(socket.readyState);
}
}
function CreateSocket()
{
socket = new WebSocket(url);
socket.onopen = function()
{
// // Web Socket is connected, send data using send()
console.log("Socket Open!");
socket.send("Here's a client message for ya!");
};
socket.onmessage = function (evt)
{
var message = evt.data;
console.log("MSG: " + message);
var obj = JSON.parse(message);
console.log(obj)
console.log(obj.type)
if(obj.type == "log"){
console.log("Recieved Log");
handleLogMessage(obj);
}
};
socket.onerror = function()
{
console.log("Error!");
}
socket.onclose = function(event)
{
// websocket is closed.
console.log(event.code);
console.log("Connection is closed...");
socket = null;
};
}
In all cases, when I call CreateSocket() a socket gets created and successfully connects to the server. I also have that CheckSocketStatus() function which returns "1" after the socket opens (Which should mean open/ready to send/receive). After that, here are the results:
Chrome:
Chrome will immediately close after connecting. The only thing I do in the onopen() function is a console.log() and a send(). If I remove the send() then the socket will stay open. I do not receive any messages from the server.
Firefox:
Firefox will keep the socket open indefinitely even if I call the send() function in onopen(). However, the server does not receive any messages from the client and vice versa. I feel like I managed to it to send client->server earlier but I could not reproduce that while testing for this question.
Microsoft Edge:
Weirdly enough, Edge works just fine. I can receive and send messages. Works exactly as intended.
Node Webkit (nw.js):
I'm also trying to write this as a nw.js app. Predictably, as it's running on chromium (or something googly), it produces the same results as Chrome.
So I'm not really sure what's going on. I'm not really a web programmer so intricate http stuff is not really my forte. I'm really hoping it's just a Local file issue with chrome/firefox and that it'll work fine on those platforms if I'm connecting to an external host. I'll try to test this tomorrow at work with some non-localhost server, and I'll update with my findings.
I guess the answer I'm looking for is what these symptoms point to and how I can get chrome/firefox/webkit to work properly.
Also what does Edge do here that the others do not?
Thanks in advance! If you need any more info from me please just ask! I didn't want to overload this question just in case there's a simple answer.
Update:
So I just tried connecting from my laptop to my desktop and the same issues still persist. So to my surprise it's not a local issue. I'm a bit stumped. I might have to look at the server code as well. I've also been told to try to use a wrapper, like socket.io, that might solve some platform dependent issues.I've worked with Socket.io/Unity before but I don't think I was having these issues (I wasn't running a server on the C# side that time, there don't seem to be any good socket.io server implementations on C#, and I'm not sure if socket.io interfaces with normal websockets). So that might point to a problem with my implementation on the C# side.
So I figured it out, thanks to gman. I looked at some of his code and noticed that he used a setting in his WebSocketBehavior class called "Ignore Extensions".
The websocket-sharp documentation has this to say:
"If it's set to true, the service will not return the Sec-WebSocket-Extensions header in its handshake response."
"I think this is useful when you get something error in connecting the server and exclude the extensions as a cause of the error."
So I guess that that header did not jive well with Chrome/Firefox. I'm still doing some testing but this solved the behavior I was seeing with those browsers.
So if you get similar errors, do that!
I'm currently working on a Vertx based application that is making use of vertx-eventbus.js as described here: http://vertx.io/docs/vertx-web/java/#_sockjs_event_bus_bridge
So the client side is using vertx-eventbus.js to send a message to server side which has SockJSHandler doing the 'bridge' to receive the message. The whole mechanism has been working fine for few months. Only very recently we now potentially need to have higher timeout limit for certain messages. If run right now, those messages always cause the following warning on the server side (and also caused the eventbus to attempt to return too early on client side with "undefined"):
Message reply handler timed out as no reply was received - it will be removed
My question is then how do you increase the timeout for the message sending in this scenario? It seems to be using the default 30 seconds timeout and I have looked everywhere (online searches Google, here at Stackoverflow, etc) with no luck. I know there is a way to set timeout when you are sending using Vertx on the backend but not when sending from vertx-eventbus.js.
Any input is very much appreciated. Let me know if there is anything else you need to better understand what I'm trying to achieve.
Thank you,
Tom
I having a frunctionality in which user can select multiple product links and can choose an option to mail those links to anyone as a new outlook mail window will be opened. Everything is working fine on my local machine but on deployed link this functionality is not working and is throwing below exception:
Exception Message : System.Runtime.InteropServices.COMException
(0x80010001): Retrieving the COM class factory for component with
CLSID {0006F03A-0000-0000-C000-000000000046} failed due to the
following error: 80010001 Call was rejected by callee. (Exception from
HRESULT: 0x80010001 (RPC_E_CALL_REJECTED)).
I saw a couple of solutions for this like this and some code samples here but nothing helped me.
Also before going for the c# code for opening new mail window, i also tried doing it in javascript but got an issue there as well (here).
Please help !!
See sending mail through outlook is not done by server side it should be done in client Side..
To open a link in mail sending client you can do
Send Mail
This will automatically open mail sending client in user machine
I am writing a node.js server and i am experiencing a weird problem
heres the code
socket.write(">> first message \0","utf8",function(){ } );
socket.write(">> second message \0","utf8",function(){ });
when i listen at the client side (ADOBE FLASH SOCKET) . it only recieves 1 message twice
and if i reverse the order of the code the message coming later only gets recieved twice , any clue on how to solve this ?
I am sure that this bug aint in programming because i have checked it like a hundred times, i also tried to make a stack explicitly then found out that node.js is supposed to mantain a stack internally ).
My node version is 0.5.1 running on windows 7 (the windows binary distributed on the website)
Try sending the second piece of data in the callback of the first:
socket.write(">> first message \0","utf8",function(){
socket.write(">> second message \0","utf8",function(){ });
} );