用java的net包写的一个小的点到点的聊天软件。用了2小时写的
源代码在线查看: message.java
package jsm;
import java.net.InetAddress;
import java.net.UnknownHostException;
//以后添加其他格式的文件
public class Message {
// 消息不能带冗余的内容
InetAddress destination;
String friendName;
byte[] ip;
String sms;
public Message() {
sms = "localhost";
friendName = Controler.myName;
try {
destination = InetAddress.getByName(null);
} catch (UnknownHostException e) {
e.printStackTrace();
}
}
public Message(String sms, byte[] ip) {
friendName = "friendName";
this.sms = sms;
this.ip = ip;
try {
destination = InetAddress.getByAddress(ip);
} catch (UnknownHostException e) {
// 弹出对话框
e.printStackTrace();
}
}
public Message(String sms, String name) {
//this.ms = ms;
this.friendName = name;
this.sms = sms;
}
public Message(String name, String sms, InetAddress destination) {
this.friendName = name;
this.sms = sms;
this.destination = destination;
}
public final InetAddress getDestination() {
return destination;
}
public final String getFriendName() {
return friendName;
}
public final String getSms() {
return sms;
}
public void setDestination(byte[] ip) {
try {
destination = InetAddress.getByAddress(ip);
} catch (UnknownHostException e) {
//会在用户输入时就要验证
e.printStackTrace();
}
}
public final void setDestination(InetAddress destination) {
this.destination = destination;
}
public final void setFriendName(String name) {
this.friendName = name;
}
public final void setSms(String sms) {
this.sms = sms;
}
}