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
猜你喜欢
请下载代码后再发表评论
     相关代码
相关代码
				 最近下载
最近下载
				 最近浏览
最近浏览
				
                qwertasdfgkwuejwjwjw     LV1
                2024年6月27日
            
            
        
                张英伟    
                2023年12月29日
            
            
                    暂无贡献等级
            
        
                youwuzuichen     LV11
                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日
            
            
        



 
                 
                 
                