SOURCE CODE for server which allows a local connection
import java.net.*;
import java.io.*;
import java.awt.*;
// set up a Server that will receive a connection from a client
// send a string to the client and close the connection
public class Server extends Frame {
TextArea display;
public Server()
{
super( "Server" );
display = new TextArea (20, 5);
add( "Center", display);
resize( 300, 150);
show();
}
public void runServer()
{
ServerSocket server;
Socket connection;
OutputStream output;
try
{
server = new ServerSocket (5000, 100 );
connection = server.accept();
display.setText ( "Connection received...\n");
display.appendText( "Sending data...\n");
output = connection.getOutputStream();
String str = new String( "Connection successful\n");
for (int i = 0; i < str.length(); i++)
output.write( (int) str.charAt( i ));
display.appendText( "Transmission complete. Closing socket.\n");
connection.close();
}
catch (IOException e)
{ e.printStackTrace(); }
}
public boolean handleEvent (Event evt)
{
if (evt.id == Event.WINDOW_DESTROY)
{
hide();
dispose();
System.exit( 0 );
}
return super.handleEvent (evt);
}
public static void main( String args[] )
{
Server serv = new Server();
serv.runServer();
}
}