I am creating an Echo Server program that accepts the server name &port number from the command line, but am unsure of how to get the info from the command line into my program. I use a BufferedReader to collect the data from the command line, but how do I use the info stored in the BufferedReader in my program. See ****** below:
Here is my code:
import java.io.*;
import java.net.*;
public class EchoServer
{
public static void main(
String args[])
{
//Declare Server Socket
ServerSocket aServerSocket = null;
//Declare Client Socket
Socket aClientSocket = null;
//Declare string used to send messages back & forth
String sline;
System.out.println("Enter server address & port number:");
//READ FROM COMMAND LINE;
***********************************************
BufferedReader br = new BufferedReader(new InputStreamReader System.in));
//FileReader fr = new FileReader(socketname);
//br = new BufferedReader(fr);
try
{
**************
//Here is where I need to use the command line info
aServerSocket = new ServerSocket(info From command line);
}//TRY
catch (IOException e)
{
//System.out.println(e);
System.out.println("Connection Failed");
}//CATCH
try
{
aClientSocket = aServerSocket.accept();
}//TRY
catch(IOException e)
{
System.out.println("Connection Failed");
}//CATCH
try
{
PrintWriter pw = new PrintWriter(aClientSocket.getOutputStream());
BufferedReader br2 = new BufferedReader (new InputStreamReader(aClientSocket.getInputStream()));
//dis = new DataInputStream(aClientSocket.getInputStream());
//ps = new PrintStream(aClientSocket.getOutputStream());
while(true)
{
sline = br.readLine();
pw.println(sline);
}//WHILE
}//TRY
catch (IOException e)
{
System.out.println(e);
}//CATCH
}//PUBLIC STATIC VOID MAIN
}//ECHO SERVER
[ January 18, 2005: Message edited by: Alex Green ]
[ January 18, 2005: Message edited by: Alex Green ]