码迷,mamicode.com
首页 > 编程语言 > 详细

java 中,socket学习

时间:2015-07-16 11:08:28      阅读:104      评论:0      收藏:0      [点我收藏+]

标签:

服务端代码:

package tt;

import java.io.*;
import java.net.*;

public class Server {
    public static void main(String args[]) {
        ServerSocket server = null;
        Socket you = null;
        DataOutputStream out = null;
        DataInputStream in = null;
        try {
            server = new ServerSocket(4331);
        } catch (IOException e) {
            System.out.println("ERROR:" + e);
        }
        try {
            you = server.accept();
            in = new DataInputStream(you.getInputStream());
            out = new DataOutputStream(you.getOutputStream());
            while (true) {
                int m = 0;
                m = in.readInt();
                out.writeUTF("你说的数对应的字符是" + (char) m);
                System.out.println("服务器收到:" + m);
                Thread.sleep(500);
            }

            

        } catch (IOException e) {
            System.out.print("" + e);

        } catch (InterruptedException e) {

        }

    }
}

 

java 中,socket学习

标签:

原文地址:http://www.cnblogs.com/Bity/p/4650436.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!