P
Paul Morrison
I am creating a program using sockets which connects to a port and sends a
text file to a socket. That socket then relays the message back, taking each
line at a time, each line is preceded by LINE. Once the socket has relayed
the whole text file it sends the string END. This class should put the text
file back together, omitting the LINE and END strings. Basically, I need to
end up with the same text file that I had initially, but it is taken apart
and then put back together again. I have chosen to use a BufferedReader to
read from the socket, and a PrintWriter to print back out to the screen. I
have the following code, but am unsure as to how to differentiate between
the actual text and the LINE and END parts. Any help would be much
appreciated.
-----
import java.io.*;
import java.net.*;
public class Agassi
{
private PrintWriter output;
private BufferedReader input;
public Agassi()
{
}
public static void main(String args[])
{
if(args.length != 2)
{
System.err.println("usage: java Agassi URL filename");
System.exit(1);
}
InetAddress inetaddress = null;
try
{
inetaddress = InetAddress.getByName(args[0]);
}
catch(UnknownHostException unknownhostexception)
{
System.err.println("URL " + args[0] + " doesn't work");
System.exit(1);
}
Socket socket = null;
try
{
socket = new Socket(args[0], 14152);
}
catch(Exception exception)
{
System.err.println("Could not connect to host");
}
try
{
BufferedReader bufferedReader = new BufferedReader(new
InputStreamReader(socket.getInputStream()));
PrintWriter printWriter = new PrintWriter(socket.getOutputStream(),
true);
}
catch (IOException ioexception)
{
System.err.println("An error has occured: " + ioexception);
}
}
}
text file to a socket. That socket then relays the message back, taking each
line at a time, each line is preceded by LINE. Once the socket has relayed
the whole text file it sends the string END. This class should put the text
file back together, omitting the LINE and END strings. Basically, I need to
end up with the same text file that I had initially, but it is taken apart
and then put back together again. I have chosen to use a BufferedReader to
read from the socket, and a PrintWriter to print back out to the screen. I
have the following code, but am unsure as to how to differentiate between
the actual text and the LINE and END parts. Any help would be much
appreciated.
-----
import java.io.*;
import java.net.*;
public class Agassi
{
private PrintWriter output;
private BufferedReader input;
public Agassi()
{
}
public static void main(String args[])
{
if(args.length != 2)
{
System.err.println("usage: java Agassi URL filename");
System.exit(1);
}
InetAddress inetaddress = null;
try
{
inetaddress = InetAddress.getByName(args[0]);
}
catch(UnknownHostException unknownhostexception)
{
System.err.println("URL " + args[0] + " doesn't work");
System.exit(1);
}
Socket socket = null;
try
{
socket = new Socket(args[0], 14152);
}
catch(Exception exception)
{
System.err.println("Could not connect to host");
}
try
{
BufferedReader bufferedReader = new BufferedReader(new
InputStreamReader(socket.getInputStream()));
PrintWriter printWriter = new PrintWriter(socket.getOutputStream(),
true);
}
catch (IOException ioexception)
{
System.err.println("An error has occured: " + ioexception);
}
}
}