[java]代码库
import java.io.*;
import java.net.*;
/**
*
* @author Administrator
*/
public class SampleClient {
public static void main(String[] arges) {
try {
//获取一个IP。null表示本机
InetAddress addr = InetAddress.getByName(null);
//打开8888端口,与服务器建立连接
Socket sk = new Socket(addr, 8688);
//缓存输入
BufferedReader in = new BufferedReader(
new InputStreamReader(sk.getInputStream()));
//缓存输出
PrintWriter out = new PrintWriter(
new BufferedWriter(
new OutputStreamWriter(
sk.getOutputStream())), true);
//向服务器发送信息
out.println("你好,我是来自于客户端的信息哦!");
//接收服务器信息
System.out.println(in.readLine());
} catch (Exception e) {
System.out.println(e);
}
}
}