please i can someone help me about creating chat massager application, please if anyone one know it please help. thanks
peter_budo 2,532 Code tags enforcer Team Colleague Featured Poster
Edited by peter_budo because: n/a
nssltd commented: Loved your link to the chat messenger search! +1
anthonydonx 0 Newbie Poster
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package java_chat_me;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import javax.swing.JTextArea;
import javax.swing.JTextField;
/**
*
* @author anthonydonx
*/
public class s {
int PORT = 3304;
InputStream inStream;
DataInputStream inDataStream;
OutputStream outStream;
DataOutputStream outDataStream;
String message="";
String received="";
public void re(JTextArea chat_s_area, JTextField chat_s_textwriter) {
try {
ServerSocket sock = new ServerSocket(PORT);
Socket conn = sock.accept();
inStream = conn.getInputStream ();
inDataStream = new DataInputStream ( inStream );
message = inDataStream.readUTF();
chat_s_area.append(message);
//conn.close();
} catch (Exception e) {
}
}
void se(JTextArea chat_s_area, JTextField chat_s_textwriter) {
// try {
// InetAddress host = InetAddress.getLocalHost();
// String diffHost = "10.215.183.1";
// Socket sock = new Socket(diffHost,PORT);
//
//
// message = chat_s_textwriter.getText();
// outStream = sock.getOutputStream();
// outDataStream = new DataOutputStream (outStream);
// outDataStream.writeUTF(message);
//
//
//
//
// } catch (Exception e) {
// }
try {
ServerSocket sock = new ServerSocket(PORT);
Socket conn = sock.accept();
inStream = conn.getInputStream ();
message = chat_s_textwriter.getText();
outStream = conn.getOutputStream();
outDataStream = new DataOutputStream (outStream);
// System.out.println("Enter your message here: ");
//outDataStream.writeUTF(message);
chat_s_area.append(message);
} catch (Exception e) {
}
}}
client
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package java_chat_me;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import javax.swing.JTextArea;
import javax.swing.JTextField;
/**
*
* @author anthonydonx
*/
public class c {
int PORT = 3304;
InputStream inStream;
DataInputStream inDataStream;
OutputStream outStream;
DataOutputStream outDataStream;
String message = "";
public void conne(JTextArea area,JTextField write){
try {
InetAddress thisIp =InetAddress.getLocalHost();
InetAddress host = InetAddress.getLocalHost();
String diffHost = thisIp.getHostAddress();
Socket sock = new Socket(diffHost,PORT);
message = write.getText();
outStream = sock.getOutputStream();
outDataStream = new DataOutputStream (outStream);
outDataStream.writeUTF(message);
} catch (Exception e) {
}
}
void re(JTextArea c_text_box, JTextField c_text_writer) {
try {
ServerSocket sock = new ServerSocket(PORT);
Socket conn = sock.accept();
inStream = conn.getInputStream ();
inDataStream = new DataInputStream ( inStream );
message = inDataStream.readUTF();
c_text_box.append(message);
// conn.close();
} catch (Exception e) {
}
}
}
Edited by peter_budo because: Adding code tags to second class
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.