okliu123456的gravatar头像
okliu123456 2013-01-14 11:50:56

java Socket套接字TCP编程开发服务端和客户端之间的通信

超级简单,没有太多实质内容的Socket服务端,客户端小程序

先运行server 再运行client OK

服务端代码如下:

public class Server {
public static void main(String[] args) {
	try {
		ServerSocket server = new ServerSocket(8800);
		Socket socket = server.accept();
		
		BufferedReader br = new BufferedReader(new InputStreamReader(socket.getInputStream()));
		
		PrintWriter pw = new PrintWriter(socket.getOutputStream());
		
		String info = null;
		while((info=br.readLine())!=null){
		 System.out.println("客户端:"+info);	
		}
		
		pw.write("我是服务器!");
		pw.flush();
		pw.close();
		br.close();
		socket.close();
	} catch (IOException e) {
		e.printStackTrace();
	}
}


最代码官方编辑于2014-10-15 9:30:59


打赏

文件名:Socket.rar,文件大小:1K 下载
最代码最近下载分享源代码列表最近下载
hemayah  LV2 2021年10月5日
kraynxn  LV8 2021年9月28日
liangge2115  LV27 2021年1月1日
lzy6312  LV14 2020年9月9日
小毛驴1220  LV6 2019年7月16日
zzarrazza  LV3 2019年6月25日
哈哈zr  LV11 2019年4月2日
73817l  LV3 2018年12月8日
369716654  LV1 2018年10月31日
Tg171017  LV12 2018年10月17日
最代码最近浏览分享源代码列表最近浏览
张英伟 2023年12月29日
暂无贡献等级
youwuzuichen  LV10 2022年9月2日
linboss  LV4 2022年8月18日
bearloadprogress  LV7 2022年5月12日
zhw2016  LV5 2022年5月3日
lyn520  LV3 2022年1月14日
a14161057831  LV2 2021年12月28日
candy123  LV1 2021年12月4日
hemayah  LV2 2021年10月5日
kraynxn  LV8 2021年9月28日
顶部 客服 微信二维码 底部
>扫描二维码关注最代码为好友扫描二维码关注最代码为好友