日期:2014-05-18 浏览次数:20655 次
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.net.Socket;
import java.net.UnknownHostException;
class meet{
/**
* @param args
*/
public static void main(String[] args) {
Socket socket = null;
try {
socket = new Socket("0.0.0.0",10000);
//获取输出流,用于客户端向服务器端发送数据
DataOutputStream dos = new DataOutputStream(socket.getOutputStream());
//获取输入流,用于接收服务器端发送来的数据
DataInputStream dis = new DataInputStream(socket.getInputStream());
//客户端向服务器端发送数据
dos.writeUTF("ABCD212165465416515156");
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
//打印出从服务器端接收到的数据
System.out.println(dis.readUTF());
//不需要继续使用此连接时,记得关闭哦
socket.close();
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}