Ubuntu 16.04 REP/REQ Over websockets question
See original GitHub issuehere is my server code:
const nanomsg = require('nanomsg');
const http = require('http');
const fs = require('fs');
const rep = nanomsg.socket('rep')
rep.bind('ws://127.0.0.1:7789');
rep.on('data', function(msg){
console.log(msg)
rep.send('received message');
})
http.createServer(function( req, res ){
fs.createReadStream( 'index.html' ).pipe( res )
}).listen( 3000 )
and my front code:
<!DOCTYPE html>
<html>
<head></head>
<body>
<div id="response">
<span> </span>
</div>
<input type="text">
<button>send</button>
<script>
var ws = new WebSocket('ws://127.0.0.1:7789',[
'rep.sp.nanomsg.org'
])
ws.onmessage = function( e ){
var reader = new FileReader() // handle binary messages
reader.addEventListener('loadend', function(){
var result = reader.result;
document.querySelector('span').textContent = result
});
reader.readAsText( e.data );
}
var button = document.querySelector('button');
var input = document.querySelector('input');
button.addEventListener('click', function( e )
{
ws.send(input.value);
input.value = '';
})
</script>
</body>
</html>
from the chrome devtools I see the upload msg,but the server client doesn’t console or reply the msg .After that, i change the req/rep to pair and pub/sub, it works. Is there anything wrong in my req/rep code? Hope your help,Best wishes
Issue Analytics
- State:
- Created 6 years ago
- Comments:6
Top Results From Across the Web
Websockets on Ubuntu 16.04 - java
I am trying to create a discord bot, and it requires being able to connect to a websocket, but however, whenever I attempt...
Read more >Fix list for IBM WebSphere Application Server V8.5
IBM WebSphere Application Server provides periodic fixes for the base and Network Deployment editions of release V8.5. The following is a complete listing ......
Read more >Ratchet PHP Websocket persistent Ubuntu 16.04
Try to use SERVERNAME instead localhost. From PHP RATCHET: Run your website and WebSocket server on the same machine using port 8080 for ......
Read more >16 WebSockets Interview Questions Web Devs Must Know
The key word in that definition is two-way: with WebSocket, both the client and the server can trigger communication with one another, and...
Read more >Websocket connetion fails on droplet with Ubuntu 14.04.
I created and tested a Java EE 7 application that uses WebSockets on my local PC. All works fine when I deploy to...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

@reqshark thanks for your recommend advice , i solved my problem successfully! Best wishes
btw @LionCoder4ever if you’re serious about using nanomsg pub/subs for websocket in the browser, I recommend using the
wsopt()socketoptseems like you already figured out that
pairandreq/repsockets are useless for doing websocket msgs over the browser in nanomsgand avoid messing with browser’s
FileReaderto decode, b/c text frames are more convenient.here’s an update to
server.jsthat we should probably fix inexamples/ws:now with text frames sockopts set, your
index.htmljavascript is a bit more reasonable: