Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Echo Server  RSS feed

 
Alex Green
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
pascal betz
Ranch Hand
Posts: 547
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
this is not a JDBC question ...


try something like:


pascal
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to IO's and Streams
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!