Ha! This is fun, I think I can get the chat program to work. I'm writing it in java. Needs some work still, but I'll post it soon.
And here it is:
Code:
import java.io.*;
import java.net.*;
import javax.swing.*;
public class Chat{
public static void main(String[] args) throws IOException {
DatagramSocket socketin = null;
boolean more = true;
int port = 5050;
try {
socketin = new DatagramSocket(port);
System.out.println("\nUDP socket (port " + port + "):");
}
catch( SocketException se ) {
se.printStackTrace();
System.exit( 1 );
}
// Set IP address
String connectIP = "192.168.1.100"; // default IP address
if (args.length == 1) {
connectIP = new String( args[0]);
}
else{
connectIP = JOptionPane.showInputDialog("Enter Connection IP address\nDefault: " + connectIP );
}
if( connectIP.equals("") )
connectIP = "192.168.1.100"; // default IP address
InetAddress addr= InetAddress.getByName( connectIP );
System.out.println( "\nConnected to: " + addr );
while (true) {
String msg = "";
msg = JOptionPane.showInputDialog("Send Message: " );
byte[] outBuf = new byte[256];
outBuf = msg.getBytes();
DatagramPacket outPacket = new DatagramPacket(outBuf, outBuf.length, addr, port);
DatagramSocket socketout = new DatagramSocket();
socketout.send(outPacket);
try {
byte[] receiveData = new byte[50000];
DatagramPacket inPacket = new DatagramPacket(receiveData, receiveData.length);
socketin.receive(inPacket);
String message = new String( inPacket.getData(), 0, inPacket.getLength() );
System.out.println( "\nMessage received: " + message );
} catch (IOException e) {
e.printStackTrace();
more = false;
}
}
}
}
Gah, my formatting is arsed.
It needs to be opened on both computers.The only problem is that the first message is always lost, because the program only listens after sending a message. So, to await a message, just send a blank message and then wait to receive.
I have crude database program I wrote in C that I could probably use to do the other one. It only ever worked with Borland Turbo C, though.