SESockets - A Prototype


The Client

The Server

The Code


public class SEClient {
    public static void main(String args[]) {
        SESocket sesock =new SESocket();
        sesock.send_it(5000,"Code Me.");
    }
}
/////////////////////////////////////////////
public class SEServer {
    public static void main(String args[]) {
        SESocket sesock =new SESocket();
        System.out.println( sesock.get_it(5000));
    }
}
//////////////////////////////////////////////
import java.net.*;
import java.util.*;
import java.io.*;
public class SESocket {

    public static void main(String args[]) {
    }
    public void SESocket() {  
    }
    public String get_it(int the_port){
        try {
            Akeystore16 K=new Akeystore16("mykey.dat");
            ServerSocket s_socket = new ServerSocket(5000);
            Socket sock = s_socket.accept();
            DataInputStream dataIn = new DataInputStream(sock.getInputStream());
            int length = dataIn.readInt();                    // read length of incoming message
            byte[] the_bytes = new byte[length];
            dataIn.readFully(the_bytes, 0, length); // read the message
            String the_string = new String(the_bytes,"ISO-8859-1");
            System.out.println( "Received undecoded: "+the_string );
            return K.Decode(the_string);
        } catch (Exception e) {
            System.out.println(e);
            return "failed";
        }
    }
    public void send_it(int the_port,String to_send){

        try {
            Akeystore16 K=new Akeystore16("mykey.dat");
            String the_message=K.Encode(to_send);
            byte[] the_bytes=the_message.getBytes("ISO-8859-1");
            InetAddress ip = InetAddress.getByName("localhost");
            Socket sock = new Socket(ip, the_port);       
            DataOutputStream dataOut = new DataOutputStream(sock.getOutputStream());
            dataOut.writeInt(the_bytes.length); // write length of the message
            dataOut.write(the_bytes);           // write the message
            System.out.println("the_bytes length Written= "+the_bytes.length);                      //
        } catch (Exception e) {
        }
    }
}