关于QuickServer的响应问题

Eric131 2014-03-11 09:28:03
使用QuickServer作为服务器,然使用socket outputStream 的Write方法,服务端不响应,不知是什么问题。没有头绪,求解,谢谢


测试代码如下

import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.Socket;
import java.net.UnknownHostException;




class SendClient
{
public static void main(String args[]) throws UnknownHostException, IOException
{
//
Socket socket = new Socket("127.0.0.1",9876);
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(socket.getOutputStream()) ;
InputStreamReader inputStreamReader = new InputStreamReader(socket.getInputStream());


String sTest = new String("Hello World");
PrintWriter pWriter = new PrintWriter(socket.getOutputStream());
OutputStream out = socket.getOutputStream();
outputStreamWriter.write(sTest);
outputStreamWriter.flush();


char[] cdata = new char[100000];
inputStreamReader.read(cdata);

String sdataString = new String(cdata);
System.out.println(sdataString);


}
}



服务端响应如下

package TestServerpage;

import java.io.IOException;
import java.net.SocketTimeoutException;

import org.quickserver.net.*;
import org.quickserver.net.server.*;



public class TestServer implements ClientBinaryHandler,ClientEventHandler,ClientCommandHandler
{

public void gotConnected(ClientHandler handler) throws SocketTimeoutException, IOException
{
handler.sendClientMsg("+++++++++++++++++++++++++++++++");
handler.sendClientMsg("| Welcome to EchoServer v 1.3 |");
handler.sendClientMsg("| Send 'Quit' to exit |");
handler.sendClientMsg("+++++++++++++++++++++++++++++++");
}

public void lostConnection(ClientHandler handler) throws IOException
{
handler.sendSystemMsg("Connection lost : " +
handler.getSocket().getInetAddress());
}

public void closingConnection(ClientHandler handler)throws IOException
{
handler.sendSystemMsg("Closing connection : " +
handler.getSocket().getInetAddress());
}

public void handleCommand(ClientHandler handler, String command)throws SocketTimeoutException, IOException
{
if(command.equals("Quit"))
{
handler.sendClientMsg("Bye ;-)");
handler.closeConnection();
}
else
{
handler.sendClientMsg("Echo : "+command);
handler.sendSystemMsg("Echo : "+command);
System.out.println("Echo : "+command);
}
}

public void handleBinary(ClientHandler arg0, byte[] arg1)
throws SocketTimeoutException, IOException {
// TODO Auto-generated method stub


}

}



...全文
165 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
Eric131 2014-03-13
  • 打赏
  • 举报
回复
自顶一下 希望大侠解答,谢谢

51,397

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧