Captive Imagination
July 31, 2010, 11:50:32 PM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News: Check out the teaser site for the first official game by Captive Imagination: http://www.galaxiesbeyond.com
 
   Home   Help Search Calendar Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: Getting connection to work  (Read 675 times)
0 Members and 1 Guest are viewing this topic.
Eggsworth
Newbie
*
Offline Offline

Posts: 15


View Profile
« on: October 08, 2009, 11:58:12 PM »

Hi, I normally dont do this, but I posted this on the JME forum as well, hoping to get a reply from darkfrog :Last Active:  July 12, 2009, 04:39:48 pm (i tried to sign up here, only to realize that the email i put in was .con instead of .com, so i waited forever for my activiation email which never came of course.)

lol so anyways... here is my situation:

we have tried to modify the chat test from JGN to work over the internet. We have only gotten it to partially work.

Basically, we want the server and the client to be runnable .jar files.
So, we simple changed the connected IP address for the client. (also port forwarded on router 9100 and 9200)

If we run client.java and server.java (modified from the chat test) inside of eclipse then it works. I can connect to my own server, my friends can connect from their houses running the client.java inside of eclipse

so we decided we wanted to take it the next step further, so that it isnt required for the JGN or Eclipse to be installed on ones computer.

so here is what we did next. we took the client.java and server.java and exported them (from inside eclipse Export -> runnable .jar) to client.jar and server.jar (remember, these are the same .java files that worked inside eclipse!)

so now we have these .jar files. On my computer, if I run the server and then the client, it connects, but this is the end of our success. With this server.jar running, none of my friends can connect with client.jar, and only I can connect. Basically all that happens is (from watching inside of Task Manager) that the client tries to connect but doesnt (it gets to like 8000k memory and stops, while a healthy client goes to 8000, and then jumps up to 20,000 after it connects)

edit:: just also tried connecting from a neighbors connection while my windows firewall was off on the computer hosting the server, that didnt change anything.

So we are at a loss.. we have tried changing some small stuff code wise in the server

namely:
Code:
InetSocketAddress reliableAddress = new InetSocketAddress((InetAddress)null, 9100);
InetSocketAddress fastAddress = new InetSocketAddress((InetAddress)null, 9200);
and
Code:
InetSocketAddress reliableAddress = new InetSocketAddress(InetAddress.getLocalHost().getHostAddress(), 9100);
InetSocketAddress fastAddress = new InetSocketAddress(InetAddress.getLocalHost().getHostAddress(), 9200);

which connects to my internal IP (but it worked in eclipse!)

so, here are the two .java files that the .jar files are exported from (basically just the chat test from JGN, except modified to "supposedly" connect to my server)

server
Code:
/**
 * Copyright (c) 2005-2006 JavaGameNetworking
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 *
 * * Redistributions of source code must retain the above copyright
 *   notice, this list of conditions and the following disclaimer.
 *
 * * Redistributions in binary form must reproduce the above copyright
 *   notice, this list of conditions and the following disclaimer in the
 *   documentation and/or other materials provided with the distribution.
 *
 * * Neither the name of 'JavaGameNetworking' nor the names of its contributors
 *   may be used to endorse or promote products derived from this software
 *   without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * Created: Jul 31, 2006
 */
package com.captiveimagination.jgn.test.chat;

import java.net.*;

import com.captiveimagination.jgn.*;
import com.captiveimagination.jgn.clientserver.*;
import com.captiveimagination.jgn.event.*;

/**
 * @author Matthew D. Hicks
 */
public class ChatServer extends DynamicMessageAdapter {
public ChatServer() throws Exception {
JGN.register(NamedChatMessage.class);

InetSocketAddress reliableAddress = new InetSocketAddress(InetAddress.getLocalHost().getHostAddress(), 9100);
InetSocketAddress fastAddress = new InetSocketAddress(InetAddress.getLocalHost().getHostAddress(), 9200);
String ii = InetAddress.getLocalHost().getHostAddress();
   System.out.println(ii);
JGNServer server = new JGNServer(reliableAddress, fastAddress);
server.addMessageListener(this);
JGN.createThread(server).start();
}


public void messageReceived(NamedChatMessage message) {
System.out.println("Message received: " + message.getPlayerName() + ", " + message.getText() + ", " + message.getDestinationPlayerId());
}

public static void main(String[] args) throws Exception {
new ChatServer();
}
}

client
Code:
* Copyright (c) 2005-2006 JavaGameNetworking
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are
 * met:
 *
 * * Redistributions of source code must retain the above copyright
 *   notice, this list of conditions and the following disclaimer.
 *
 * * Redistributions in binary form must reproduce the above copyright
 *   notice, this list of conditions and the following disclaimer in the
 *   documentation and/or other materials provided with the distribution.
 *
 * * Neither the name of 'JavaGameNetworking' nor the names of its contributors
 *   may be used to endorse or promote products derived from this software
 *   without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * Created: Jul 31, 2006
 */
package com.captiveimagination.jgn.test.chat;

import com.captiveimagination.jgn.JGN;
import com.captiveimagination.jgn.clientserver.JGNClient;
import com.captiveimagination.jgn.event.DebugListener;
import com.captiveimagination.jgn.event.DynamicMessageAdapter;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.InetAddress;
import java.net.InetSocketAddress;

/**
 * @author Matthew D. Hicks
 */
public class ChatClient extends DynamicMessageAdapter implements ActionListener {
private JGNClient client;
private String nickname;
private JTextPane textPane;
    private JTextField textField;

public ChatClient() throws Exception {
JGN.register(NamedChatMessage.class);

client = new JGNClient();
client.addMessageListener(this);
client.addMessageListener(new DebugListener("ChatClient>"));
JGN.createThread(client).start();

InetSocketAddress reliableServerAddress = new InetSocketAddress(InetAddress.getByName("24.234.70.244"), 9100);
InetSocketAddress fastServerAddress = new InetSocketAddress(InetAddress.getByName("24.234.70.244"), 9200);

client.connectAndWait(reliableServerAddress, fastServerAddress, 5000);
nickname = JOptionPane.showInputDialog("Connection established to server\n\nPlease enter the name you wish to use?");
initGUI();
}

private void initGUI() {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); // TODO fix
frame.setTitle("Chat Client - " + nickname);
frame.setSize(300, 300);
Container c = frame.getContentPane();
        c.setLayout(new BorderLayout());
        textPane = new JTextPane();
        textPane.setText("");
        textPane.setEditable(false);
        c.add(BorderLayout.CENTER, textPane);
        textField = new JTextField();
        textField.addActionListener(this);
        c.add(BorderLayout.SOUTH, textField);
        frame.setVisible(true);
}

public void actionPerformed(ActionEvent evt) {
String txt = textField.getText().trim();
if (txt.length() > 0) {
NamedChatMessage message = new NamedChatMessage();
message.setPlayerName(nickname);
message.setText(txt);

if (txt.startsWith("srv")) client.sendToServer(message);
else if (txt.startsWith("0")) client.sendToPlayer(message, (short) 0);
else client.broadcast(message);

textField.setText("");
writeMessage(client.getPlayerId(), nickname, message.getText());
}
}

public void messageReceived(NamedChatMessage message) {
writeMessage(message.getPlayerId(), message.getPlayerName(), message.getText());
}


private void writeMessage(short playerId, String playerName, String text) {
String message = "[" + playerName + ":" + playerId + "]: " + text;
if (textPane.getText().length() == 0) {
            textPane.setText(message);
        } else {
            textPane.setText(textPane.getText() + "\r\n" + message);
        }
}

public static void main(String[] args) throws Exception {
new ChatClient();
}
}

So why this discrepancy between inside of eclipse, and in jar file???

Any help would be awesome, we have been plugging at this for a couple days now. Thanks!
« Last Edit: October 09, 2009, 12:21:09 AM by Eggsworth » Logged
darkfrog
Administrator
Inspired Imagination
*****
Offline Offline

Posts: 2650


View Profile
« Reply #1 on: October 09, 2009, 08:15:27 AM »

Try changing your server's binding address to the explicit local IP address for your machine and see if that makes any difference.  I've had problems with this before.
Logged
Eggsworth
Newbie
*
Offline Offline

Posts: 15


View Profile
« Reply #2 on: October 09, 2009, 10:26:21 AM »

changing the server to
Code:
InetSocketAddress reliableAddress = new InetSocketAddress(InetAddress.getByName("192.168.1.100"), 9100);
InetSocketAddress fastAddress = new InetSocketAddress(InetAddress.getByName("192.168.1.100"), 9200);

and exporting and running it as a .jar, when attempting to connect a client from my neighbors internet, the client still does not start (IE: its not connecting) and i can still connect from my computer the server is hosted on.

whats killing me is that we could get all this to work inside eclipse.. but not outside


EDIT: PROBLEM SOLVED!!!

ok.. here is what happened.
I decided to go into the client and put a new JFrame for each action the client was doing, so i could literally see where it was stopping.
so i exported it as a .jar and sent it off to my laptop for testing. Guess what?? The changes I made didnt take place!! This caused me to wonder, why is it that I changed this code, but yet, it doesnt process this new code on the .jar i just made. Well, when i looked closer at the .jar exporter, the server and client.java files i was exporting had the same name as the JGN ones... So, I decided to rename them. After renaming the .java files and exporting to .jars, it all works!!

and it works using
Code:
InetSocketAddress reliableAddress = new InetSocketAddress(InetAddress.getLocalHost().getHostAddress(), 9100);
InetSocketAddress fastAddress = new InetSocketAddress(InetAddress.getLocalHost().getHostAddress(), 9200);

So... thanks for all your help and stuff.
« Last Edit: October 09, 2009, 10:57:39 AM by Eggsworth » Logged
darkfrog
Administrator
Inspired Imagination
*****
Offline Offline

Posts: 2650


View Profile
« Reply #3 on: October 10, 2009, 08:11:22 AM »

Congrats! I'm glad you got it figured out.
Logged
Eggsworth
Newbie
*
Offline Offline

Posts: 15


View Profile
« Reply #4 on: October 11, 2009, 01:30:27 PM »

Well, I need a little more help.

I have moved on to the point where I want to have a little JME in my 'game'

But, through implementation, I have come to understand that I am confused about how to do this.

What I have so far is a server and a client that connects to it. I am trying to send a message by using client.broadcast(message) but the server doesnt receive it. The reason for this is because I do not understand how to set up message listeners and handlers.

Can you explain to me how exactly these work?


EDIT:: I have been messing around with this and I now have a client -> server model but there is 1 problem.
when a client calls client.broadcast(message); only the other clients recieve the information and not the client that broadcasted. Is that how it is supposed to be?


Also... I am having a launch problem again. Everything runs perfectly in eclipse, and i can even connect from other computers through eclipse, but when i export it to .jar files, this time it seems to be choking on the
Code:
       new Thread() {
         public void run() {
         app.start();
         }
        }.start();

because if i put any joption panes after it to tell me info, the one to pop up is frozen (have to end task in task manager) and it doesnt display the text.
So, if I put a joption pane inside of the initsystem of my MainGame, it doesnt show me, which means when it calls app.start() it doesnt know what its doing. Why would it be doing this?

I put a app.start(); call before starting the new thread, just to see what would happen. In eclipse it opens a new options pane (where in JME you select fullscreen and hit start game) but, when I export it to the .jar, it doesnt do ANYTHING! so... it seems the jar isnt working correctly with app.start();
but.. it does see app, because i can call a boolean from app and it will display it as true (which is correct) This is quite the interesting problem. Any ideas?

Another EDIT:: I exported a soley single player game I had made using JME and JMEPhysics. Guess what? As a .jar it doesnt start either. So, this isnt a JGN problem as I thought it was, but rather a JME as .jar problem.
« Last Edit: October 11, 2009, 06:19:03 PM by Eggsworth » Logged
darkfrog
Administrator
Inspired Imagination
*****
Offline Offline

Posts: 2650


View Profile
« Reply #5 on: October 11, 2009, 06:28:43 PM »

EDIT:: I have been messing around with this and I now have a client -> server model but there is 1 problem.
when a client calls client.broadcast(message); only the other clients recieve the information and not the client that broadcasted. Is that how it is supposed to be?

Yes, that is exactly how broadcast is intended to work.
Logged
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 0.196 seconds with 20 queries.