How do I set up the web server for this server.java so that a client can connect to server by its ip?
Sorry I can 't type Chinese now. Can you give me a basic idea?
These two apps only work in LAN, how do I make it work through internet?
Code:
//server
import java.net.*;
import java.io.*;
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.Color;
import java.util.Random;
import javax.swing.*;
import javax.swing.filechooser.*;
import javax.swing.border.*;
public class Server extends Frame implements ActionListener, WindowListener
{
static ServerSocket listenSocket;
static Socket connection;
private static int maxConnections=0;
//final JFileChooser fc = new JFileChooser();
static String message;
static TextField hostDisplay, portDisplay;
static TextArea logDisplay, msgDisplay;
Panel topPanel;
Panel middlePanel;
Panel buttonPanel;
Button sendButton, quitButton;
public static final int DEFAULT_PORT = 8901;
static String host;
static int port;
public Server ( String s)
{
super ( s );
buildUI ();
} // end Server constructor
public void connectClient ( )
{
if ( ! ( portDisplay.getText () ).equals ( " " ) ) port = Integer.parseInt ( portDisplay.getText () );
else port = DEFAULT_PORT;
} // end connectClient
public static void main ( String [ ] args )
{
Server serverFrame = new Server( "Server " );
serverFrame.addWindowListener ( serverFrame );
int i=0;
if ( ! ( portDisplay.getText () ).equals ( " " ) ) port = Integer.parseInt ( portDisplay.getText () );////
else port = DEFAULT_PORT;////
try
{
ServerSocket listener = new ServerSocket(port);
Socket server;
logDisplay.setText ( "Server running on "+host+ ", port "+port+ "\n " );/////
while((i++ < maxConnections) || (maxConnections == 0))
{
doComms connection;