is posible different language on web socket?

i have the problem when i want to try web socket technology on my application. but i want to ask about requiretment of web socket.

1) is posible i'm using Server with javascript language ex is socket.io

var io = require('socket.io').listen(3001);

io.sockets.on('connection', function (socket) {
  socket.emit('news', {hello: 'can you hear me'});
});

and the client using Java language example is socket.io.java i'm using this method to get message from server

public void onMessage(JSONObject json, IOAcknowledge ack) {
                Log.d("We received a message: " , json.toString());
            }

with my socket server is

SocketIO socket = new SocketIO("http://127.0.0.1:3001/news");

2) is support to all machine? or browser?i'm newbie on web socket programing, please help me

thanks for your answer...


Yes, you can build the server in any language you want, but web sockets are not a simple socket, they are sockets that "follow" a specific protocol, so make sure you read the specification of this protocol and implement it on your server so any browser will be able to stablish a connection to it.

And you can also write a client in any language, but if you're not using javascript then I don't see why you would use web sockets instead of using just a simple socket. But if you want to, just take a look at what data a browser sends to a web socket server and emulate it from your own client.


To elaborate on Delta's answer, "websockets" is a variation of the HTTP protocol where the client sends an HTTP request message, the server sends an HTTP response, and then the client and server use the still-open TCP/IP connection to do "other things". The request and response contain special headers which allow the client and server to agree to use the connection in this way.

In order for this to work, the client and server both need to understand at least a subset of the HTTP protocol in order to do the initial "handshake". Hence you can't simply use a websocket client to talk to a plain socket server ... or vice versa. (If you try to do that, both ends will see unexpected stuff / protocol errors. And the websocket end should promptly close its end of the TCP/IP connection.)

Having said that, a websocket client and a websocket server can be implemented in just about any modern programming language. (And the same goes for plain socket clients and servers.)


Sockets are an operating system thing. You can use them with any language providing the relevant interface or glue code to the operating system calls implementing them (eg on Linux: socket(2), connect(2), accept(2), listen(2), poll(2), recv(2) etc...)

But if you are newbie about sockets, I strongly suggest reading a good network programming book.

链接地址: http://www.djcxy.com/p/7784.html

上一篇: 本地PHP支持Web套接字吗?

下一篇: 在网络套接字上可以使用不同的语言吗?