lostwake15
Senior Newbie 
|
 |
«
Posted
2009-09-03 03:24:50 » |
|
I have two questions.
1. I have seen many examples of server/client network application but none that involve the client being an applet. Is it possible to have the client be run from an applet on a web page? If so how is this done and how is it different from a normal client. 2. I would like to start by hosting a server from my home computer, which will run a simple game from an applet on a website hosted from another service provider. The thing I do not understand is that in every example I have seen the HOST is shown to be a “localhost” what must I change this too to let the client run from another computer?
Im sorry if these are confusing questions. Any example code or website links would be appreciated. If anyone wants me to clarify or provide any other information please let me know.
Thanks in advance.
|
|
|
|
Nate
|
 |
«
Reply #1 - Posted
2009-09-03 09:39:00 » |
|
1. I'm not very familiar with applets. It is Java code running in an applet, so yes, you can connect a socket and do whatever you want. I'm just not sure about applet security. 2. You can use DynDNS: https://www.dyndns.com/Sign up then go to My Hosts and create a host. This will give you a domain like somegame.dnsalias.com that you set in DynDNS to point to your external IP. This way you can run your server, etc on your own box and use somegame.dnsalias.com in your game.
|
|
|
|
lostwake15
Senior Newbie 
|
 |
«
Reply #2 - Posted
2009-09-03 10:17:20 » |
|
For questions 2, the reason I was looking into hosting from home was so that I would not have to signup through any other program or service. Is there a way to have the client applet connect strait to the server running on the home computer?
|
|
|
|
Games published by our own members! Check 'em out!
|
|
steveyO
|
 |
«
Reply #3 - Posted
2009-09-03 10:51:50 » |
|
If the client applet is hosted on the same web/application server as where your java server application is then you can connect to it using Sockets with no security issues (using your IP address instead of Localhost). If you want to host your client applet on a different server to your home computer then connecting with sockets will throw an security expection (as the applet doesnt originate from the host).. I think you can overcome this by signing the applet (but never done this so not sure, don't like this approach as the client would have to approve security popups on their applets).
|
|
|
|
Nate
|
 |
«
Reply #4 - Posted
2009-09-03 23:36:43 » |
|
For questions 2, the reason I was looking into hosting from home was so that I would not have to signup through any other program or service. Is there a way to have the client applet connect strait to the server running on the home computer?
Yes. This is what I proposed.
|
|
|
|
|
|
lostwake15
Senior Newbie 
|
 |
«
Reply #6 - Posted
2009-09-05 00:36:01 » |
|
Thanks for all your input I will look into all of this information.
|
|
|
|
lostwake15
Senior Newbie 
|
 |
«
Reply #7 - Posted
2009-09-05 00:59:39 » |
|
Hey guys I am trying out “dyndns” like you said and I created an account and a host with the name lucreenliven.game-host.org. Now I am unsure what to do next. Here are sample codes of a server and a client for a simple chat program from “Killer Java Game Programming” and I wanted to know what I need to do to get the server to run on my comp and have any other computer load the client and be able to go on? Any help would be great. Thanks in advance. Note: These are just the to top levels of the codes, if you want all of the files let me know. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
| import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.io.*; import java.net.*;
public class ChatClient extends JFrame implements ActionListener { private static final int PORT = 1234; private static final String HOST = "lucreenliven.game-host.org"; private Socket sock; private PrintWriter out; private JTextArea jtaMesgs; private JTextField jtfMsg; private JButton jbWho;
public ChatClient() { super("Chat Client"); initializeGUI(); addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { closeLink(); } });
setSize(300,450); setVisible(true);
makeContact(); }
private void initializeGUI() { Container c = getContentPane(); c.setLayout( new BorderLayout() );
jtaMesgs = new JTextArea(7, 7); jtaMesgs.setEditable(false); JScrollPane jsp = new JScrollPane( jtaMesgs); c.add( jsp, "Center");
JLabel jlMsg = new JLabel("Message: "); jtfMsg = new JTextField(15); jtfMsg.addActionListener(this); jbWho = new JButton("Who"); jbWho.addActionListener(this);
JPanel p1 = new JPanel( new FlowLayout() ); p1.add(jlMsg); p1.add(jtfMsg);
JPanel p2 = new JPanel( new FlowLayout() ); p2.add(jbWho);
JPanel p = new JPanel(); p.setLayout( new BoxLayout(p, BoxLayout.Y_AXIS)); p.add(p1); p.add(p2);
c.add(p, "South");
}
private void closeLink() { try { out.println("bye"); sock.close(); } catch(Exception e) { System.out.println( e ); }
System.exit( 0 ); }
private void makeContact() { try { sock = new Socket(HOST, PORT); BufferedReader in = new BufferedReader( new InputStreamReader( sock.getInputStream() ) ); out = new PrintWriter( sock.getOutputStream(), true ); new ChatWatcher(this, in).start(); } catch(Exception e) { System.out.println(e); } }
public void actionPerformed(ActionEvent e) { if (e.getSource() == jbWho) out.println("who"); else if (e.getSource() == jtfMsg) sendMessage(); }
private void sendMessage() { String msg = jtfMsg.getText().trim(); if (msg.equals("")) JOptionPane.showMessageDialog( null, "No message entered", "Send Message Error", JOptionPane.ERROR_MESSAGE); else { out.println(msg); } }
public void showMsg(final String msg) { Runnable updateMsgsText = new Runnable() { public void run() { jtaMesgs.append(msg); jtaMesgs.setCaretPosition( jtaMesgs.getText().length() ); } }; SwingUtilities.invokeLater( updateMsgsText ); }
public static void main(String args[]) { new ChatClient(); }
}
import java.net.*; import java.io.*;
public class ChatServer { static final int PORT = 1234; private ChatGroup cg;
public ChatServer() { cg = new ChatGroup(); try { ServerSocket serverSock = new ServerSocket(PORT); Socket clientSock;
while (true) { System.out.println("Waiting for a client..."); clientSock = serverSock.accept(); new ChatServerHandler(clientSock, cg).start(); } } catch(Exception e) { System.out.println(e); } }
public static void main(String args[]) { new ChatServer(); }
} |
|
|
|
|
Nate
|
 |
«
Reply #8 - Posted
2009-09-05 05:10:21 » |
|
Please use the "code" tags when posting code.
I don't understand. Run the server on one computer and run the client on another (or the same) computer. Are you asking how to run a Java program in general?
|
|
|
|
lostwake15
Senior Newbie 
|
 |
«
Reply #9 - Posted
2009-09-05 05:30:24 » |
|
Ok ill use a code tag next time. Sorry
I want to be able to run the server on my computer and let anyone else who has the client code to be able to run it on his or her computer and connect to the server. Right now I am using “localhost” which mean I can only run the client on my computer, I signed up with dyndns.com but I don’t know how to change my code to make it run with dyndns.com and enable any computer to use the client code.
|
|
|
|
Games published by our own members! Check 'em out!
|
|
h3ckboy
|
 |
«
Reply #10 - Posted
2009-09-05 09:58:16 » |
|
would be nice if you editted in the code tags, but oh well  . anyways, what you are looking for is port forwarding. It is an option in your router. Just forward anything on say port 3333 to your server ip address(lan). And then just replace localhost with lucreenliven.game-host.org. hope I could help  , h3ckboy P.S: if you need anyone outside your lan to test then just post here.
|
|
|
|
|
Nate
|
 |
«
Reply #11 - Posted
2009-09-05 11:00:26 » |
|
The client code you posted connects to "lucreenliven.game-host.org". If this is what you setup with DynDNS, this will resolve to your external IP. Next, as h3ckboy mentioned, you need to make port 1234 open to the internet so that clients can connect. Check any software and hardware firewalls you may have and configure them to open the 1234 TCP port. You can test DynDNS, at a command line run "ping lucreenliven.game-host.org". If it reports your IP address, it works. You can find your external IP address here (which I find pretty damned funny  ): http://moanmyip.com/If you are going to run a server from home, realize your IP address could change. When this happens DynDNS will be pointing to the wrong place. I run a program every few hours that updates DynDNS with whatever my current IP address is. The program I use is "DNSerSvc", but you can Google for "DynDNS updater". Some routers can also update a dynamic DNS service. I don't actually run a game server, I just like to be able to remote into my home machines. I also run it on friends and families computers, so I can take them over with VNC and fix the computers when they mess them up. 
|
|
|
|
h3ckboy
|
 |
«
Reply #12 - Posted
2009-09-05 11:14:10 » |
|
a more efficient way (but less prefered by dyndns). Is just to go to the dynamic dns section on your router. You can just send you IP address without installing any software  .
|
|
|
|
|
DzzD
|
 |
«
Reply #13 - Posted
2009-09-05 18:56:48 » |
|
some points : 1 - you may have trouble to make it working for Applet running on other computer and for applet running locally at the same time, if you want both to work you have to modify your local host table to something like : lucreenliven.game-host.org 127.0.0.1 this way external user will resolve lucreenliven.game-host.org to your public Internet IP adresse and when you will run the applet locally it will resolve lucreenliven.game-host.org with 127.0.0.1 2 - if you are connecting to internet using a router (probably the case) you must redirect external acces to the TCP port you use to your local computer IP so that when someone connect to your public internet IP using the TCP port XXXX it will be redirected to your computer local network IP using the port XXXX NB.: probably not the case but if you are connecting to internet using a proxy the server will probably not work cause the proxy wont let your computer act as a server (it wont redirect external connection to your computer) 3 - to enable the applet to connect to the server it must be run from it, this mean that you must have an HTTP server where external user can launch the applet from, like http://lucreenliven.game-host.org/myapplet.html must be working and must return a web page containing the applet
|
|
|
|
lostwake15
Senior Newbie 
|
 |
«
Reply #14 - Posted
2009-09-09 21:24:53 » |
|
So I have been trying for days to get a sever running on my home computer but despite this wonderful help I have been getting I cannot get it to work. I have a complicated internet connection with many routers and switched in place and I cannot figure it out. So as an alternative I think I’m going to break down and get a Virtual Private Server (VPS). Can anyone give me some information on what I will need to know to run this server? The program I will be using is http://www.virtualservernode.com/bronze-node.html. I under stand there is much more to it than hosting a regular WebPages from a service provider but I don’t know what to expect, I am still fairly new to the Webmaster world and have little formal training on the matter. Any information would be helpful, and if I’m getting in way over my head please let me know. I am willing to learn any system or program to make this work. Thanks in advance.
|
|
|
|
SimonH
|
 |
«
Reply #15 - Posted
2009-09-09 21:59:04 » |
|
Not exactly sure what you're after, but Google's AppEngine gives you 10 free app deployments based on servlets. Works good but has high (300ms) latency.
|
|
|
|
lostwake15
Senior Newbie 
|
 |
«
Reply #16 - Posted
2009-09-09 22:10:12 » |
|
Well I’m going to get my own “server” so I’m assuming I will need software, and a cpanel and other things. I’m wondering how hard this is to do with limited knowledge of servers in general.
I’m looking for information and maybe a tutorial on how to set up a server and what software I will need.
|
|
|
|
ddyer
|
 |
«
Reply #17 - Posted
2009-09-09 23:37:36 » |
|
Forget about server hardware and basic server software. You need a VPS (virtual private server) which can be rented very cheaply, and will come running a complete suite of everything you need except your own software. Most VPS are linux, but windows versions also exist. If you have no familiarity with unix, quite a bit of head-banging can be expected if you try to use a unix based machine. Either way, you won't need to worry much about the standard server software, only setting up your application in that environment.
|
|
|
|
|
|
|
ddyer
|
 |
«
Reply #19 - Posted
2009-09-10 08:16:25 » |
|
Don't rush to rent a server. There's no reason to do so until you have a fully functional web site running at home. Assuming your usual development environment is windows, load windows version of the tools you use on your development machine, develop, and and test locally.
The VPS ought to be already running apache, perl, mysql and lots of other common unix tools. Thenjust uploa d copies of fully debugged programs and web pages.
You've obviously got a lot to learn. You can probably find some very useful tutorials. Have fun.
|
|
|
|
|
|