Java版socket编程实现带语音聊天和文件传送功能


本资源是本人前面发过的一个局域网聊天工具的升级版。具体功能有: 1.采用了全新的界面风格(新增) 2.实现了基本文字聊天功能 3.实现了基本文件传送功能 4.实现了发送窗口抖动的功能 5.实现了语音聊天的功能(新增) 资源内容包括源程序和打包后的可执行jar文件,以及要用到的所有jar包; 代码保证可用,如有问题请留言,代码较规范,结构清晰,相信对学习java socket编程和swing界面开发的朋友有一定的帮助。 注:main函数在MainFrame类
资源截图
代码片段和文件信息
package bean;

import org.apache.commons.codec.DecoderException;

import util.BasicUtils;

/**
 * 消息协议格式:
 * 包序号+命令字+用户名+‘:‘+主机名+‘:‘+消息正文
 * 包序号:占8Byte,采用当前毫秒数转换为字节数组,这也是包的发送时间
 * 命令字:即head字段,是长度为2的字符串;每个命令字在Global类中定义
 * @author DELL
 *
 */
public class Message {
private long seq; //包序号
private String userName;
private String hostName;
private String head; //消息头,表明消息的类型
private String data; //消息正文

public Message(){

}

public Message(String userNameString hostNameString head String message) {
this.seq = System.currentTimeMillis();
this.head = head;
this.data = message;
this.hostName = hostName;
this.userName = userName;
System.out.println(“====发送消息:“+seq+this.head+this.userName+“:“+this.hostName+“:“+this.data);
}

public Message(long seq String userNameString hostNameString head String message) {
this.seq = seq;
this.head = head;
this.data = message;
this.hostName = hostName;
this.userName = userName;
}

public String getHead() {
return head;
}
public void setHead(String head) {
this.head = head;
}
public String getData() {
return data;
}
public void setData(String data) {
this.data = data;
}
public long getSeq() {
return seq;
}

public void setSeq(long seq) {
this.seq = seq;
}

public String getUserName() {
return userName;
}

public void setUserName(String userName) {
this.userName = userName;
}

public String getHostName() {
return hostName;
}

public void setHostName(String hostName) {
this.hostName = hostName;
}

public byte[] toBytes() throws DecoderException{
byte[] seqBytes = BasicUtils.longToByteArray(this.seq);
byte[] otherBytes = (this.head+this.userName+“:“+this.hostName+“:“+this.data).getBytes();
byte[] msgBytes = new byte[seqBytes.length+otherBytes.length];
for(int i=0;i if(i msgBytes[i] = seqBytes[i];
else
msgBytes[i] = otherBytes[i-seqBytes.length];
}
return msgBytes;
}


}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----
     目录           0  2014-02-25 09:43  MyMessager2.1
     文件         417  2014-02-25 09:31  MyMessager2.1.classpath
     文件         389  2014-02-23 16:26  MyMessager2.1.project
     目录           0  2014-02-25 09:42  MyMessager2.1.settings
     文件         598  2014-02-23 00:52  MyMessager2.1.settingsorg.eclipse.jdt.core.prefs
     目录           0  2014-02-25 09:43  MyMessager2.1in
     目录           0  2014-02-25 09:42  MyMessager2.1inean
     文件        2822  2014-02-25 09:31  MyMessager2.1ineanMessage.class
     文件        3192  2014-02-25 09:31  MyMessager2.1ineanTbMsg.class
     文件        1552  2014-02-25 09:31  MyMessager2.1ineanUser.class
     目录           0  2014-02-25 09:42  MyMessager2.1indata
     文件       10240  2014-02-25 09:28  MyMessager2.1indatauserdata.db
     目录           0  2014-02-25 09:42  MyMessager2.1inexception
     文件         453  2014-02-25 09:31  MyMessager2.1inexceptionMessageOverflowException.class
     目录           0  2014-02-25 09:42  MyMessager2.1inhandler
     文件        8370  2014-02-25 09:31  MyMessager2.1inhandlerMessageReceiver.class
     文件        4564  2014-02-25 09:31  MyMessager2.1inhandlerMessageSender.class
     文件        3563  2014-02-25 09:31  MyMessager2.1inhandlerVoiceReceiver.class
     文件        3709  2014-02-25 09:31  MyMessager2.1inhandlerVoiceSender.class
     目录           0  2014-02-25 09:42  MyMessager2.1inimages
     文件       25813  2014-02-21 23:38  MyMessager2.1inimages1.jpg
     文件       86994  2014-02-21 23:51  MyMessager2.1inimages2.jpg
     文件         781  2013-11-28 22:38  MyMessager2.1inimagesaccept.png
     文件         652  2013-06-20 21:15  MyMessager2.1inimagesaccepting.png
     文件         733  2013-11-28 22:22  MyMessager2.1inimagesadd.png
     文件        2035  2014-02-22 16:10  MyMessager2.1inimagesapp48.png
     文件        2942  2014-02-22 16:10  MyMessager2.1inimagesapp64.png
     文件         733  2013-11-30 13:38  MyMessager2.1inimagesasket_put.png
     文件         738  2013-11-30 13:38  MyMessager2.1inimagesasket_remove.png
     文件         789  2013-11-28 17:33  MyMessager2.1inimagesell.png
     文件        1308  2014-02-22 16:08  MyMessager2.1inimagesell24.png
............此处省略131个文件信息

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件举报,一经查实,本站将立刻删除。

发表评论

评论列表(条)