51,397
社区成员




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