I’m interested(besides other matters) in making a small little chat application, where if person A starts it up, and person B starts it up, they can both perform chatting operations
this can be very simple with no gui at all, where should i start…
I’m interested(besides other matters) in making a small little chat application, where if person A starts it up, and person B starts it up, they can both perform chatting operations
this can be very simple with no gui at all, where should i start…
java.net.*
I’m not sure what else to tell you with as general a question as this.
(If you don’t even know what a TCP socket is, then get a decent beginning book on networking.)
[quote]I’m interested(besides other matters) in making a small little chat application, where if person A starts it up, and person B starts it up, they can both perform chatting operations
this can be very simple with no gui at all, where should i start…
[/quote]
Chat programs need a server which they use as a means of a lobby, or a common meeting place where people can locate one-another so they can start chatting.
You can use proper IRC servers for this if you like, or setup your own server which will have to be anchored to the Internet – i.e. have a permanent domain name.
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
import java.net.*;
import java.io.*;
import java.security.*;
final class MySecurityManager extends SecurityManager {
public void checkPermission(Permission perm) {}
public void checkPermission(Permission perm, Object context) {}
}
public class IrcApplet extends Applet implements Runnable {
// IRC Stuff..
private Socket s;
private BufferedWriter bw;
private BufferedReader br;
private Thread t;
// GUI Stuff..
private boolean isStandalone = false;
private BorderLayout borderLayout1 = new BorderLayout();
private Panel panel1 = new Panel();
private TextField tfIrcText = new TextField();
private BorderLayout borderLayout2 = new BorderLayout();
private Panel panel2 = new Panel();
private Panel panel3 = new Panel();
private Panel panel4 = new Panel();
private Panel panel5 = new Panel();
private Panel panel6 = new Panel();
private BorderLayout borderLayout3 = new BorderLayout();
private Panel panel7 = new Panel();
private Panel panel8 = new Panel();
private Panel panel9 = new Panel();
private TextArea textArea1 = new TextArea();
private Panel panel10 = new Panel();
private BorderLayout borderLayout4 = new BorderLayout();
private Panel panel11 = new Panel();
private Button btnConnect = new Button();
private BorderLayout borderLayout5 = new BorderLayout();
private Panel panel12 = new Panel();
private Panel panel13 = new Panel();
//Get a parameter value
public String getParameter(String key, String def) {
return isStandalone ? System.getProperty(key, def) :
(getParameter(key) != null ? getParameter(key) : def);
}
//Construct the applet
public IrcApplet() {
}
//Initialize the applet
public void init() {
try {
jbInit();
} catch (Exception e) {
e.printStackTrace();
}
}
//Component initialization
private void jbInit() throws Exception {
this.setLayout(borderLayout1);
panel1.setLayout(borderLayout2);
tfIrcText.setText("");
tfIrcText.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
tfIrcTextActionPerformed(e);
}
});
panel6.setLayout(borderLayout3);
textArea1.setColumns(80);
textArea1.setEditable(false);
textArea1.setRows(20);
textArea1.setText("");
panel10.setLayout(borderLayout4);
btnConnect.setLabel("Connect");
btnConnect.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
btnConnectActionPerformed(e);
}
});
panel5.setLayout(borderLayout5);
this.add(panel1, BorderLayout.NORTH);
panel1.add(tfIrcText, BorderLayout.CENTER);
panel1.add(panel2, BorderLayout.SOUTH);
panel1.add(panel3, BorderLayout.WEST);
panel1.add(panel4, BorderLayout.EAST);
panel1.add(panel5, BorderLayout.NORTH);
panel5.add(panel10, BorderLayout.CENTER);
panel10.add(panel11, BorderLayout.WEST);
panel11.add(btnConnect, null);
panel5.add(panel12, BorderLayout.EAST);
panel5.add(panel13, BorderLayout.WEST);
this.add(panel6, BorderLayout.CENTER);
panel6.add(textArea1, BorderLayout.CENTER);
panel6.add(panel7, BorderLayout.SOUTH);
panel6.add(panel8, BorderLayout.EAST);
panel6.add(panel9, BorderLayout.WEST);
}
//Get Applet information
public String getAppletInfo() {
return "Applet Information";
}
//Get parameter info
public String[][] getParameterInfo() {
return null;
}
void btnConnectActionPerformed(ActionEvent e) {
try {
s = new Socket("irc.shadowworld.net", 6667);
InputStream is = s.getInputStream();
OutputStream os = s.getOutputStream();
InputStreamReader isr = new InputStreamReader(is);
OutputStreamWriter osw = new OutputStreamWriter(os);
bw = new BufferedWriter(osw);
br = new BufferedReader(isr);
t = new Thread(this);
t.start();
processInput("NICK WizKid");
processInput(":WizKid USER WizKid TEST TEST :FirstName LastName");
} catch (Exception ex) {
ex.printStackTrace();
}
}
public void processInput(String text) {
try {
bw.write(text);
bw.newLine();
bw.flush();
} catch (IOException ex) {
ex.printStackTrace();
}
}
private void respondToOutput(String value) {
if (value.startsWith("PING")) {
value = value.replaceFirst("PING", "PONG");
processInput(value);
}
}
public void addToOutput(String outputString) {
textArea1.append(outputString);
textArea1.append("\r\n");
}
public void run() {
String line = null;
while (Thread.currentThread() == t) {
try {
line = br.readLine();
if (line != null) {
addToOutput(line);
respondToOutput(line);
} else {
t = null;
}
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
void tfIrcTextActionPerformed(ActionEvent e) {
processInput(tfIrcText.getText());
tfIrcText.setText(null);
}
}
I wrote the above applet, it connects to an IRC server and lets you chat (although very primitively of course)
If you’re going the IRC way, you’d need to implement some of the IRC guideline as specified in RFC1459 at http://www.cse.ohio-state.edu/cgi-bin/rfc/rfc1459.html for instance.
If you’re going for a chat applet, you could also use the information here http://forum.java.sun.com/thread.jsp?forum=54&thread=383859 to sign the applet and host it on whatever site you want to.
Hope this helps