Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3440026
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T08:22:59+00:00 2026-05-18T08:22:59+00:00

I’m trying some multiplayer game ideas out at the moment and am trying to

  • 0

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 environment is Eclipse on the main machine, and notepad + Google Chrome on this laptop.

I’m creating the websocket using javascript at the client end, and using the java.net.Socket at the server end.

I’ve managed to get a connection acknowledged at both ends, but can’t seem to send or recieve any data between them without the client closing the connection (doesn’t even error; just seems to freak out at something and call socket.close).

Does anyone have any ideas?

Here’s some code:

Client:

<script type="text/javascript">
var socket;

function init() {
    socket = new WebSocket("ws://192.168.0.3:10000");
    socket.onopen = function() { alert('OPEN: ' + socket.readyState); }
    socket.onmessage = function (msg) { alert('DATA: ' + msg.data); }
    socket.onerror = function (msg) { alert('DATA: ' + msg.data); }
    socket.onclose = function () { alert('CLOSED: ' + socket.readyState); }
}

function onClick() {
    socket.send("YAY!");
}
</script>

Server:

public static void main(String args[])
{
    System.out.printLn("Websocket server test");

    ServerSocket connectSocket = null;

    try
    {
        Socket clientSocket;
        connectSocket = new ServerSocket(10000);
        System.out.printLn("Waiting for connection...");
        clientSocket = connectSocket.accept();
        System.out.printLn("Got one!");

        PrintWriter out = new PrintWriter(clientSocket.getOutputStream(), true);
        BufferedReader in = new BufferedReader(
            new InputStreamReader(clientSocket.getInputStream()));

        for(int i=0;i<100;i++) //Shit but easy
        {
            String data = in.readLine();
            System.out.printLn("Got data: " + data);
            out.printLn("YAY!");
        }
    }
    catch (IOException e)
    {
        System.out.printLn("You fail: " + e.getMessage());
    }

    System.out.printLn("Finished!");
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T08:22:59+00:00Added an answer on May 18, 2026 at 8:22 am

    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
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
Basically, what I'm trying to create is a page of div tags, each has
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I have a small JavaScript validation script that validates inputs based on Regex. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.