当前位置: 代码迷 >> J2SE >> Please help me, I have a server.java and client.java to test the file transmission on internet,该怎么解决
  详细解决方案

Please help me, I have a server.java and client.java to test the file transmission on internet,该怎么解决

热度:457   发布时间:2016-04-24 13:39:49.0
Please help me, I have a server.java and client.java to test the file transmission on internet
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;
  相关解决方案