sockets - Communicating with WebSocket server using a TCP class -


would possible send , receive data/messages/frames , websocket server interface using standard tcp class?

or need fundamentally change tcp class?

if possible, show me little example of how like? (programming language doesn't matter)
example found node.js code represents simple tcp client:

var net = require('net');  var client = new net.socket(); client.connect(1337, '127.0.0.1', function() {     console.log('connected');     client.write('hello, server!'); });  client.on('data', function(data) {     console.log('received: ' + data); }); 

maybe show me have changed make communicate websocket.

websockets protocol runs on tcp/ip, detailed in standard's draft.

so, in fact, it's using tcp/ip connection (tcp connection class / object) implement protocol's specific handshake , framing of data.

the plezi framework, written in ruby, that.

it wraps tcpsocket class in it's wrapper called connection (or sslconnection) , runs data through protocol input layer (the wsprotocol , httpprotocol classes) app layer , through protocol output layer (the wsresponse , httpresponse classes) connection:

 tcp/ip receive -> protocol input layer ->      app -> protocol output -> tcp/ip send 

a websocket handshake starts http request. can read the plezi's handshake code here*.

* handshake method receives httprequest, httpresponse , app controller , uses them send required http reply before switching websockets.

once handshake complete, each message received made of message frames (one or more). can read frame decoding , message extraction code used in plezi framework here.

before sending messages back, divided 1 or more websocket protocol frames using code , sent using tcp/ip connection.

there plenty of examples out there if google. i'm sure of them in programming language prefer.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -