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:
InetSocketAddress reliableAddress = new InetSocketAddress((InetAddress)null, 9100);
InetSocketAddress fastAddress = new InetSocketAddress((InetAddress)null, 9200);
and
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
/**
* 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
* 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!