用socket实现的文件服务器(2)

该博客展示了ForumFileDao类的代码,包含多个业务逻辑方法,如获取主题贴内容、回帖列表,以及发帖、续贴、回贴、删帖等操作。这些方法通过ForumFileClient与服务器通信,使用Socket进行数据传输,部分方法还涉及QQ信息。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

/**
* 业务逻辑层调用的接口
* @author HongSoft
*/
public class ForumFileDao
{
/**
* 得到主题贴内容
* 主题贴只写一行
* @param forumId
* @param topicId
* @return
*/
public static String getTopicContent(int forumId, int topicId)
{
String content = "";
ForumFileClient ffc = new ForumFileClient();
try
{
ffc.getOut().println("0" + "\0x1e" + forumId + "\0x1e" + topicId);
content = ffc.getIn().readLine();
}
catch (Exception e)
{
e.printStackTrace();
}
ffc.closeSocket();
return content;
}
/**
* 得到回帖列表
* @param forumId
* @param topicId
* @return
*/
public static List getReplyContent(int forumId, int topicId)
{
List replyList=new ArrayList();
String str="";
ForumFileClient ffc = new ForumFileClient();
try
{
ffc.getOut().println("1" + "\0x1e" + forumId + "\0x1e" + topicId);
while((str=ffc.getIn().readLine())!=null)
{
String[] strs=str.split("\0x1e");
ReplyRef rr=new ReplyRef();
rr.setUserId(strs[0]);
rr.setAddTime(strs[1]);
rr.setContent(strs[2]);
replyList.add(rr);
}
}
catch (Exception e)
{
e.printStackTrace();
}
ffc.closeSocket();
return replyList;
}
/**
* 发帖
* @param forumId
* @param topicId
* @return
*/
public static void addTopic(int forumId, int topicId,String content)
{
ForumFileClient ffc = new ForumFileClient();
try
{
ffc.getOut().println("2" + "\0x1e" + forumId + "\0x1e" + topicId+"\0x1e"+content);
}
catch (Exception e)
{
e.printStackTrace();
}
ffc.closeSocket();
}
/**
* 续贴(主题贴只写一行)
* @param forumId
* @param topicId
* @return
*/
public static void resumeTopic(int forumId, int topicId,String content)
{
ForumFileClient ffc = new ForumFileClient();
try
{
ffc.getOut().println("3" + "\0x1e" + forumId + "\0x1e" + topicId+"\0x1e"+content);
}
catch (Exception e)
{
e.printStackTrace();
}
ffc.closeSocket();
}
/**
* 回贴
* @param forumId
* @param topicId
* @return
*/
public static void addReply(int forumId, int topicId,String content,String qq,String replyTime)
{
ForumFileClient ffc = new ForumFileClient();
try
{
ffc.getOut().println("4" + "\0x1e" + forumId + "\0x1e" + topicId+"\0x1e"+content+"\0x1e"+qq+"\0x1e"+replyTime);
}
catch (Exception e)
{
e.printStackTrace();
}
ffc.closeSocket();
}
/**
* 删主题贴(同时它的回贴也应该删除)
* @param forumId
* @param topicId
* @return
*/
public static void deleteTopic(int forumId, int topicId)
{
ForumFileClient ffc = new ForumFileClient();
try
{
ffc.getOut().println("5" + "\0x1e" + forumId + "\0x1e" + topicId);
}
catch (Exception e)
{
e.printStackTrace();
}
ffc.closeSocket();
}
/**
* 删某个回贴(但回贴数并不做改变)
* @param forumId
* @param topicId
* @return
*/
public static void deleteReply(int forumId, int topicId,int replyId)
{
ForumFileClient ffc = new ForumFileClient();
try
{
ffc.getOut().println("6" + "\0x1e" + forumId + "\0x1e" + topicId+"\0x1e"+replyId);
}
catch (Exception e)
{
e.printStackTrace();
}
ffc.closeSocket();
}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值