用java的net包写的一个小的点到点的聊天软件。用了2小时写的

源代码在线查看: message.java

软件大小: 8 K
上传用户: feigo156
关键词: java net 软件
下载地址: 免注册下载 普通下载 VIP

相关代码

				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;
					}
				
				}
							

相关资源