java 小程序错误
本帖最后由 dongdelw 于 2013-09-04 16:26:34 编辑
程序出错:开始没反应,随后出现错误如图
——————————————————————————
___________________________
源程序:
Client.java
————————————————————
import java.io.*;
import java.net.*;
public class Client{
public static void main(String[] args) throws Exception{
Socket client = new Socket("127.0.0.1",5678);
DataInputStream in=new DataInputStream(client.getInputStream());
DataOutputStream out=new DataOutputStream(client.getOutputStream());
out.writeUTF("hello Server");
String readServer;
while(true){//读取服务器数据,需要延时等待。
readServer=in.readUTF();
System.out.println(readServer);
out.writeUTF("Thanks Server");
if(readServer.equals("Thanks Client"))break;
}
}
}
-------------------------------------------------
Server.java
------------------------
import java.net.*;
import java.io.*;
public class Server{
public static void main(String args[]) throws Exception{
ServerSocket server=new ServerSocket(5678);//创建ServerSocket对象,等待客户端访问
Socket user=server.accept();//响应客户端的请求,获取的客户端创建的Socker对象。
DataOutputStream out=new DataOutputStream(user.getOutputStream());
DataInputStream in=new DataInputStream(user.getInputStream());
out.writeUTF("hello Client");
String readClient;
while(true){ //读取客户端数据,需要延时等待。
readClient=in.readUTF();
System.out.println(readClient);