mrniko / netty-socketio Goto Github PK
View Code? Open in Web Editor NEWSocket.IO server implemented on Java. Realtime java framework
License: Apache License 2.0
Socket.IO server implemented on Java. Realtime java framework
License: Apache License 2.0
Invoke on client side websocket.close (disconnect from socket). No disconnect event.
And no disconnect by timeout for websocket.
after 20 second i get a onDisconnect event, i have to refresh to get a new connection
Implement "acknowledgments" feature support.
Review follow links:
http://vimeo.com/34496203
http://readthedocs.org/docs/tornadio2/en/latest/acknowledgments/
have to use sendMessage(object.toString()) to actually send a Json object
Add an ability to share your message to all the users connected on the same channel
Currently, there's no way to retrieve the hostname and/or port the server is listening to.
Provide com.corundumstudio.socketio.SocketIOServer with a getter for its configuration property (and thus being able to get the hostname and port), and/or the hostname and port values directly
It's important to have ability to plugin any json parser, not only jackson.
Hi all,
Is there a way to perform authentication of the clients? Here is an example of socketionode server http://howtonode.org/socket-io-auth
Thanks
Implement ssl support.
http://stackoverflow.com/questions/6599470/node-js-socket-io-with-ssl
To reproduce:
1.
[sinnus@myhost netty-socketio]$ curl -i http://localhost:7878/socket.io/1/
HTTP/1.1 200 OK
Content-Type: text/plain; charset=UTF-8
Connection: keep-alive
Content-Length: 63
702eefd0-a70f-4cba-9f4c-cc6b316ed183:2:60:xhr-polling,websocket
[sinnus@myhost netty-socketio]$ curl -i http://localhost:7878/socket.io/1/xhr-polling/702eefd0-a70f-4cba-9f4c-cc6b316ed183
HTTP/1.1 200 OK
Content-Type: text/plain; charset=UTF-8
Connection: keep-alive
Content-Length: 3
1::
No disconnect event on server side by timeout
Could you write documentation (guide, etc) for implementation SocketIOServer listeners?
I downloaded netty into Eclipse, and wrote a simple class similar to the "ChatLauncher" in the demo. When I ran the class from Eclipse, I got this error:
Exception in thread "main" java.lang.NullPointerException
at com.corundumstudio.socketio.handler.ResourceHandler.addResource(ResourceHandler.java:80)
at com.corundumstudio.socketio.handler.ResourceHandler.(ResourceHandler.java:72)
at com.corundumstudio.socketio.SocketIOPipelineFactory.start(SocketIOPipelineFactory.java:117)
at com.corundumstudio.socketio.SocketIOServer.start(SocketIOServer.java:79)
at DemoServer.main(DemoServer.java:20)
I found out that it happens when the resource handler tries to get ''/static/flashsocket/WebSocketMain.swf''.
When a client using xhr-polling disconnects from a heart-beat timeout, any DisconnectListeners registered on that namespace are never notified.
I've run the example, find out that chrome and ie9 dont work as good as ff.
Sometimes the connection takes two times to build and sometimes it couldn't be made and throw the exception as follows:
148 [main] INFO com.corundumstudio.socketio.SocketIOServer - SocketIO server started at port: 9092
5323 [New I/O worker #7] ERROR com.corundumstudio.socketio.handler.PacketHandler - Exception occurs
java.io.IOException: An established connection was aborted by the software in your host machine
at sun.nio.ch.SocketDispatcher.read0(Native Method)
at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:25)
at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:237)
at sun.nio.ch.IOUtil.read(IOUtil.java:204)
at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:236)
at org.jboss.netty.channel.socket.nio.NioWorker.read(NioWorker.java:59)
at org.jboss.netty.channel.socket.nio.AbstractNioWorker.processSelectedKeys(AbstractNioWorker.java:471)
at org.jboss.netty.channel.socket.nio.AbstractNioWorker.run(AbstractNioWorker.java:332)
at org.jboss.netty.channel.socket.nio.NioWorker.run(NioWorker.java:35)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
am in missing sth. or a bug or what? pls give some help. thanks in advance.
Hi
In the readme document an server example have this line
config.setListener(handler);
But config seems no longer have this method
Chees
Szymon
When a worker thread gets stuck (for example, in an endless loop or a deadlock), it seems that the server keeps spawning new threads to do the same task, which may make the situation worse.
To check this, I created a small server that, when accepting the "HANG" event, just does a for(;;) loop. This is what I see in the log:
INFO 09:53:46 [New I/O worker #6 ]: start
INFO 09:53:46 [New I/O worker #6 ]: looping forever
INFO 09:54:38 [New I/O worker #8 ]: start
INFO 09:54:38 [New I/O worker #8 ]: looping forever
INFO 09:54:58 [New I/O worker #10 ]: start
INFO 09:54:58 [New I/O worker #10 ]: looping forever
INFO 09:55:18 [New I/O worker #12 ]: start
INFO 09:55:18 [New I/O worker #12 ]: looping forever
INFO 09:55:38 [New I/O worker #14 ]: start
INFO 09:55:38 [New I/O worker #14 ]: looping forever
INFO 09:55:58 [New I/O worker #16 ]: start
INFO 09:55:58 [New I/O worker #16 ]: looping forever
...
Hi.
In some cases different messages (usually few first in session) from one session are processed simultaneously.
It doesn't look normal for me, or it expected behavior?
netty-socketio -- today's shapshot
Netty 3.3.1.Final
Logs:
TRACE 0114-1736:09,177 48081 [New I/O server worker #2-1] [] SocketIOEncoder - Out message: d55fe943-c43a-491c-b167-0308bca83e21:60:60:websocket,flashsocket,xhr-polling - sessionId: d55fe943-c43a-491c-b167-0308bca83e21 - channelId: 3021676
DEBUG 0114-1736:09,183 48087 [New I/O server worker #2-1] [] AuthorizeHandler - New sessionId: d55fe943-c43a-491c-b167-0308bca83e21 authorized
TRACE 0114-1736:09,205 48109 [New I/O server worker #2-2] [] SocketIOEncoder - Out message: 1:: - sessionId: d55fe943-c43a-491c-b167-0308bca83e21 - channelId: 27791931
INFO 0114-1736:09,206 48110 [New I/O server worker #2-2] [] PublisherSocketIoNetworkSession - Network session id=1 created.
DEBUG 0114-1736:09,207 48111 [New I/O server worker #2-2] [] XHRPollingTransport - Client for sessionId: d55fe943-c43a-491c-b167-0308bca83e21 was created
TRACE 0114-1736:09,226 48130 [New I/O server worker #2-3] [] SocketIOEncoder - Out message: - sessionId: null - channelId: 20858451
TRACE 0114-1736:09,226 48130 [ New I/O server worker #2-3 ] [] PacketHandler - In message: ?5?3:::1?159?3::: ...some data 1... sessionId: d55fe943-c43a-491c-b167-0308bca83e21
TRACE 0114-1736:11,354 50258 [New I/O server worker #2-5] [] SocketIOEncoder - Out message: - sessionId: null - channelId: 29569194
TRACE 0114-1736:11,355 50259 [ New I/O server worker #2-5 ] [] PacketHandler - In message: 3::: ...some data 2... sessionId: d55fe943-c43a-491c-b167-0308bca83e21
DEBUG 0114-1736:11,355 50259 [ New I/O server worker #2-5 ] [] PublisherSocketIoNetworkSession - N_IN processing some data 2 (S)
WARN 0114-1736:11,355 50259 [New I/O server worker #2-5] [] PublisherSocketIoNetworkSession - Try to process message from not fully initialized client. Session id=1. Skipped.
DEBUG 0114-1736:12,094 50998 [ New I/O server worker #2-3 ] [] PublisherSocketIoNetworkSession - N_IN processing some data 1 (S)
TRACE 0114-1736:12,110 51014 [New I/O server worker #2-3] [PSINS_1] SocketIOEncoder - Out message: 3::: ... response on some data #1 ... - sessionId: d55fe943-c43a-491c-b167-0308bca83e21 - channelId: 18584303
Now socket.io context is hardcoded
If you run chat socket.io (http://narod.ru/disk/49278924001.b5fa5142d169f8acde06d0cbbb1937fa/chat.zip.html) you can see xhr-polling doesn't send heartbeat messages ("2:::") because long polling has own heartbeat like behavior.
As a test, I started a server with no listeners at all:
final SocketIOServer networkServer = new SocketIOServer(config);
networkServer.start();
I then sent it a message from the "event-index.html" of the demo.
I got a null pointer exception, with no explanation about what I did wrong....
I would be happy to get a clearer error message:
ERROR 09:56:22 [New I/O worker #2 PacketHandler]: Exception occurs
java.lang.NullPointerException
at com.fasterxml.jackson.databind.ObjectMapper.treeToValue(ObjectMapper.java:1807)
at com.corundumstudio.socketio.parser.JacksonJsonSupport$EventDeserializer.deserialize(JacksonJsonSupport.java:161)
at com.corundumstudio.socketio.parser.JacksonJsonSupport$EventDeserializer.deserialize(JacksonJsonSupport.java:1)
at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:2796)
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:1988)
at com.corundumstudio.socketio.parser.JacksonJsonSupport.readValue(JacksonJsonSupport.java:218)
at com.corundumstudio.socketio.parser.Decoder.decodePacket(Decoder.java:160)
at com.corundumstudio.socketio.parser.Decoder.decodePackets(Decoder.java:259)
at com.corundumstudio.socketio.handler.PacketHandler.messageReceived(PacketHandler.java:67)
at com.corundumstudio.socketio.handler.ResourceHandler.messageReceived(ResourceHandler.java:117)
at org.jboss.netty.handler.codec.replay.ReplayingDecoder.messageReceived(ReplayingDecoder.java:415)
at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:268)
at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:255)
at com.corundumstudio.socketio.transport.WebSocketTransport.receivePackets(WebSocketTransport.java:141)
at com.corundumstudio.socketio.transport.WebSocketTransport.messageReceived(WebSocketTransport.java:90)
at com.corundumstudio.socketio.transport.XHRPollingTransport.messageReceived(XHRPollingTransport.java:95)
at com.corundumstudio.socketio.handler.AuthorizeHandler.messageReceived(AuthorizeHandler.java:99)
at com.corundumstudio.socketio.handler.PacketHandler.messageReceived(PacketHandler.java:79)
at com.corundumstudio.socketio.handler.ResourceHandler.messageReceived(ResourceHandler.java:117)
at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:296)
at org.jboss.netty.handler.codec.frame.FrameDecoder.unfoldAndFireMessageReceived(FrameDecoder.java:462)
at org.jboss.netty.handler.codec.replay.ReplayingDecoder.callDecode(ReplayingDecoder.java:536)
at org.jboss.netty.handler.codec.replay.ReplayingDecoder.messageReceived(ReplayingDecoder.java:435)
at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:268)
at org.jboss.netty.channel.Channels.fireMessageReceived(Channels.java:255)
at org.jboss.netty.channel.socket.nio.NioWorker.read(NioWorker.java:88)
at org.jboss.netty.channel.socket.nio.AbstractNioWorker.process(AbstractNioWorker.java:107)
at org.jboss.netty.channel.socket.nio.AbstractNioSelector.run(AbstractNioSelector.java:313)
at org.jboss.netty.channel.socket.nio.AbstractNioWorker.run(AbstractNioWorker.java:88)
at org.jboss.netty.channel.socket.nio.NioWorker.run(NioWorker.java:178)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603)
at java.lang.Thread.run(Thread.java:679)
I am running a socket.io server on a Windows 2003 / Java 1.7. Sometimes it works OK, but sometimes, just when I start() the server, I get this error message:
Exception in thread "main" org.jboss.netty.channel.ChannelException: Failed to c
reate a selector.
at org.jboss.netty.channel.socket.nio.AbstractNioSelector.openSelector(A
bstractNioSelector.java:338)
at org.jboss.netty.channel.socket.nio.AbstractNioSelector.(Abstrac
tNioSelector.java:96)
at org.jboss.netty.channel.socket.nio.AbstractNioWorker.(AbstractN
ioWorker.java:51)
at org.jboss.netty.channel.socket.nio.NioWorker.(NioWorker.java:45
)
at org.jboss.netty.channel.socket.nio.NioWorkerPool.createWorker(NioWork
erPool.java:45)
at org.jboss.netty.channel.socket.nio.NioWorkerPool.createWorker(NioWork
erPool.java:28)
at org.jboss.netty.channel.socket.nio.AbstractNioWorkerPool.newWorker(Ab
stractNioWorkerPool.java:99)
at org.jboss.netty.channel.socket.nio.AbstractNioWorkerPool.init(Abstrac
tNioWorkerPool.java:69)
at org.jboss.netty.channel.socket.nio.NioWorkerPool.(NioWorkerPool
.java:39)
at org.jboss.netty.channel.socket.nio.NioWorkerPool.(NioWorkerPool
.java:33)
at org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory.(NioServerSocketChannelFactory.java:149)
at org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory.(NioServerSocketChannelFactory.java:131)
at org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory.(NioServerSocketChannelFactory.java:115)
at com.corundumstudio.socketio.SocketIOServer.start(SocketIOServer.java:
76)
:188)
Caused by: java.io.IOException: Unable to establish loopback connection
at sun.nio.ch.PipeImpl$Initializer.run(Unknown Source)
at sun.nio.ch.PipeImpl$Initializer.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at sun.nio.ch.PipeImpl.(Unknown Source)
at sun.nio.ch.SelectorProviderImpl.openPipe(Unknown Source)
at java.nio.channels.Pipe.open(Unknown Source)
at sun.nio.ch.WindowsSelectorImpl.(Unknown Source)
at sun.nio.ch.WindowsSelectorProvider.openSelector(Unknown Source)
at java.nio.channels.Selector.open(Unknown Source)
at org.jboss.netty.channel.socket.nio.AbstractNioSelector.openSelector(A
bstractNioSelector.java:336)
... 15 more
Caused by: java.net.ConnectException: Connection timed out: connect
at sun.nio.ch.Net.connect0(Native Method)
at sun.nio.ch.Net.connect(Unknown Source)
at sun.nio.ch.Net.connect(Unknown Source)
at sun.nio.ch.SocketChannelImpl.connect(Unknown Source)
at java.nio.channels.SocketChannel.open(Unknown Source)
... 25 more
If profile exclude-swf-files is used, resulting .jar file lacks folder static/... (which is Ok for the ones like me providing the SWF files for flashsocket from a separate HTTP server, see #42) but socket.io server throws NPE since there are hardcoded references to such files under static/...
Exception in thread "main" java.lang.NullPointerException
at com.corundumstudio.socketio.handler.ResourceHandler.addResource(ResourceHandler.java:79)
at com.corundumstudio.socketio.handler.ResourceHandler.(ResourceHandler.java:71)
at com.corundumstudio.socketio.SocketIOPipelineFactory.start(SocketIOPipelineFactory.java:117)
at com.corundumstudio.socketio.SocketIOServer.start(SocketIOServer.java:83)
at com.sabre.jpm.server.nio.services.SJPMSocketIoServerNio.start(SJPMSocketIoServerNio.java:112)
at com.sabre.jpm.server.nio.services.SJPMHTTPServerNio.start(SJPMHTTPServerNio.java:78)
at com.sabre.jpm.server.Main.start(Main.java:94)
at com.sabre.jpm.server.Main.main(Main.java:107)
Is it possible to create a Java socket.io client that will connect to the socket.io server (without Javascript)?
It seems the package contains a SocketIOClient class, so, it's only a matter of documentation - how to use it to connect to a server directly.
PacketEncoder should encode directly to ChannelBuffer without StringBuilder usage.
I'm having difficulty with functions of the form:
void addEventListener(String eventName, DataListener<Object> listener);
void addJsonObjectListener(DataListener<Object> listener);
It does not seem to be documented anywhere what this Object
type actually is, nor how to extract useful information from one. Your demos don't serve as a useful example, either; they simply forward the object without observing it.
At the very least, you need better documentation - if you know this is a specific JSON-object class, or if it's some sort of dynamic class achieved by reflective magic, that should be documented somewhere. Even better, the type should be specific to whatever you're actually using.
Error for any other requests wich not comply socket.io protocol
Try to use simple socket.io client (like in example) and the following handler:
SocketIOListener handler = new SocketIOListener() {
@Override
public void onMessage(SocketIOClient client, String message) {
System.out.println("MESSAGE: " + message);
client.sendJsonObject(message);
client.sendJsonObject(message);
}
@Override
public void onDisconnect(SocketIOClient client) {
System.out.println("DISCONNECT");
}
@Override
public void onConnect(final SocketIOClient client) {
System.out.println("CONNECT");
}
@Override
public void onJsonObject(SocketIOClient client, Object obj) {
System.out.println("MESSAGE JSON: " + obj);
client.sendJsonObject(obj);
client.sendJsonObject(obj);
}
};
Make sense for incoming and committing messages.
when i export the project as a jar file, ResourceHandler could not load the swf file as getClass().getResource(resourcePath) [ResourceHandler.java line 78] cannt recognize the path:
"D:\workspace\netty-socketio-1.0.0-SNAPSHOT.jar!\static\flashsocket\WebSocketMainInsecure.swf.
And ie6 turns out to use the flashsocket as the transport way.
Hello!
First of all, thank you for your great work!
I have a question: is your library available in maven public repositories? I've failed to find it there.
If yes, could you provide me an address of the repository?
And if no, could you please publish it?
Take a look at http://socket.io/#how-to-use section "Restricting yourself to a namespace."
AuthorizeMessage and other classes in this package look to be immutable. They do not have setter methods. Adding final to the class variables maybe a good practice. Even the class variables like String, UUID are immutable so this is optional, but can be done for consistency sake.
reproduce:
onPacket handler put sleep longer then timout for example 60 secounds
send one message
result
client disconnected
resolution
send response http ok before onPacket.
Very nice project. Namespace is supported. Is room also supported?
The project very good about performance and code style very clear. But, i don't see flashsocket support. Could you please add it.
Add ability to customize SocketIOPipelineFactory to add own handler
Following the example on the readme, I built an example application with server and client. The client code in the readme is:
var socket = io.connect('http://localhost:81');
This worked well on my computer, but when I tried to deploy both client and server to another machine, and tried to access the client from my machine, it didn't work, because the "connect" looked for the server on my machine (which is, for the client, the "localhost"...)
Maybe this is a documentation issue - explain how to deploy a client-server application.
Does this framework support uploading a file from client to server? If not, what workaround I can do? Thanks.
For logging purposes, it would be great to know what transport (websocket, XHR polling, etc.) is actually being used by the client
As I serve the socket.io.js and *.swf files from a separate HTTP server, I would like to create the netty-socketio .jar file not including such static files.
in order to create lots of one-to-one chat room dynamically, which do you recommend? namespace or EventListener and Y? Thanks.
Try to request the following url:
Sometimes it is useful to route log messages, created anywhere on the server during a request, to the relevant client, in order to let the client trace the progress of his request.
I wrote a class that accomplishes this, for log4j. It uses the MDC feature. In order to use it, the server should set the MDC value to the actual client, at the beginning of each request, for example,
server.addEventListener("myevent", Request.class, new DataListener<Request>() {
@Override public void onData(SocketIOClient client, Request request, AckRequest ackRequest) {
MDC.put("client", client);
/* code to handle the request and reply to the client */
}
});
The appender can be used from the log4j properties file, for example:
log4j.rootLogger=info, socket
log4j.appender.socket = <package-name>.SocketAppender
Here is the appender itself:
package <package-name>;
import org.apache.log4j.AppenderSkeleton;
import org.apache.log4j.spi.LoggingEvent;
import com.corundumstudio.socketio.SocketIOClient;
/**
* Send log messages to web clients.
*
* @author Erel Segal Halevi
* @since 2013-01-01
*/
public class SocketAppender extends AppenderSkeleton {
@Override protected void append(LoggingEvent event) {
SocketIOClient client = (SocketIOClient)event.getMDC("client");
String eventLevel = event.getLevel().toString().toLowerCase();
if (client!=null)
client.sendEvent(eventLevel, event.getLoggerName()+": "+event.getMessage());
}
@Override public boolean requiresLayout() {
return false;
}
@Override public void close() {
// nothing to close
}
}
This will create a different event for each log level, for example, for an "info" log level, the client will receive an "info" event, etc. Possible client code for handling these events:
socket.on('trace', function(data) {
// ignore trace events
});
socket.on('debug', function(data) {
console.log(data);
});
socket.on('info', function(data) {
console.info(data);
});
socket.on('warn', function(data) {
console.warn(data);
});
socket.on('error', function(data) {
console.error(data);
});
socket.on('fatal', function(data) {
alert("A fatal error has occured on the server: "+data);
});
Update project to use latest jackson version.
SocketIOClient has dependency from ChannelFuture.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.