import java.io.*;
import java.applet.Applet;
import java.net.*;
import javax.swing.*;
import java.awt.*;
import java.util.*;
public class ClientApplet extends Applet implements Runnable {
public static TextArea chat;
static PrintStream os = null;
static Socket clientSocket = null;
public void init() {
chat = new TextArea(10,40);
add(chat);
chat.append("Hey!");
}
public void start() {
new Thread(this).start();
}
public void run() {
// communicate with server here
Socket s = null;
try {
s = new Socket(getParameter("host"), Integer.valueOf(getParameter("port")));
//s = new Socket("localhost", 4444);
InputStream in = s.getInputStream();
os = new PrintStream(clientSocket.getOutputStream());
int buf = -1;
while ((buf = in.read()) != '.') {
chat.append("\n" + buf);
}
chat.append("\nIn read: " + in.read() + "\nServer sent: " + in);
}catch(Exception e) {
e.printStackTrace();
}
finally {
try {
s.close();
} catch(IOException e)
{ }
}
}
}
|