Java websocket host?

前端 未结 5 1900
滥情空心
滥情空心 2020-12-16 01:04

I\'m trying some multiplayer game ideas out at the moment and am trying to create a Java application to serve a web browser based multiplayer game.

My development en

相关标签:
5条回答
  • 2020-12-16 01:22

    Rather than going the painful way of implementing the spec in Java, I'd suggest that you use an existing solution like jWebSocket.

    Also if you don't mind leaving Java land, I'd also suggest that you take a look at Node.js for your Server.

    Doing both Server and Client in JavaScript will save you lots of time and lots of Code, especially since JSON just doesn't fit that well into static land. Also creating multiplayer servers in Node.js is trivial, since the event based, single threaded model fits the whole thing pretty well.

    More information on WebSocket can be found in the FAQ. In case you want to get started with Node.js take a look at the TagWiki.

    shameless plug follows

    For two multiplayer games that were written using Node.js take a look at my GitHub page.

    0 讨论(0)
  • 2020-12-16 01:24

    I would suggest our high level solution: Bristleback Server. It contains both server and client, you can choose from several existing low level WebSocket engines (like Jetty, Netty or Tomcat), developing with Bristleback is extremally fast and easy. However, it is still Beta and we are working hard to release a final 1.0.0 version. If you use Maven, we have provided an archetype with ready to use web application.

    I am one of the co-creators of Bristleback Server.

    0 讨论(0)
  • 2020-12-16 01:25

    Try this lib - https://github.com/mrniko/netty-socketio

    Based on high performance socket lib Netty. It supports latest protocol of Socket.IO server. Several transports including websocket.

    On web side use Socket.IO client javascript lib:

    <script type="text/javascript">
        var socket = io.connect('http://localhost:81', {
          'transports' : [ 'websocket' ],
          'reconnection delay' : 2000,
          'force new connection' : true
        });
        socket.on('message', function(data) {
             // here is your handler on messages from server
        });
    
        // send object to server
        var obj = ...
        socket.json.send(obj);
    </script>
    
    0 讨论(0)
  • 2020-12-16 01:38

    I can't help you with sockets, but can i suggest you to use RMI technology? I'm trying to make a multiplayer rpg in java, and i'm using remote method invocation between server and client (it is possible also call-back the client from the server). It's really easy use it, but it uses TCP instead of UDP. In LAN experience there is no lag, on internet I have not tried yet. However, if your game tolerates just a bit retard between request and response, there is no problem. This is the link of my project, Client and Server classes may be useful for you.

    0 讨论(0)
  • 2020-12-16 01:40

    As no one yet really answered your question: the reason it does not work, is because you are not implementing the websocket specification. It takes of lot more work to setup a proper websocket connection than just opening a socket, as the websocket connection setup starts with a HTTP upgrade request. Your client is closing the connection, because it does not receive a positive answer on the upgrade request to start with.

    0 讨论(0)
提交回复
热议问题