本帖最后由 陈琦 于 2012-10-21 23:00 编辑
- public class TestTcp {
- public static void main(String[] args) {
- try {
- Socket s = new Socket("127.0.0.1",8866);
- BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
- BufferedWriter bw = new BufferedWriter((new OutputStreamWriter(s.getOutputStream())));//包装成BufferedWriter后写入服务端读取为空??
- // OutputStream bw = s.getOutputStream();
- String str = br.readLine();
- bw.write(str);
- s.close();
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }
复制代码 只有客户端的代码,需要看服务端的话,我再贴。 |