急,用socket,接收到的数据不对?
server方代码
public class Server1
{
private ServerSocket ss;
public static final int DAYTIME_PORT = 13;
public static void main(String args[]) throws IOException
{
Server1 server = new Server1();
server.go();
}
public void go() throws IOException
{
Socket s = null;
ss = new ServerSocket(DAYTIME_PORT, 5);
for (;;) {
s = ss.accept();
BufferedWriter out = new BufferedWriter(
new OutputStreamWriter(s.getOutputStream()));
//System.out.println("dddd");
out.write("Current time from server:" +
(new Date()).toString() + "\n");
out.close();
s.close();
}
}
}
客户端代码
public class clientTest {
/** Creates a new instance of clientTest */
public clientTest(String host) {
this.host = host;
}
public static final int DAYTIME_PORT = 13;
String host;
Socket s;
public static void main(String args[]) throws IOException
{
clientTest client = new clientTest("localhost");
client.go();
}
public void go() throws IOException
{
s = new Socket(host, DAYTIME_PORT);
BufferedReader i=new BufferedReader(
new InputStreamReader(s.getInputStream()));
System.out.println(i.read());
i.close();
s.close();
}
}
客户端收到是:67。用socket,接收到的数据不对?为什么?