首页

安卓客户端和服务端交互(socket)

java

2020-7-16

package com.example.videonetty;

import io.netty.bootstrap.Bootstrap;  
import io.netty.channel.Channel;
import io.netty.channel.EventLoopGroup;  
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioSocketChannel;  
  

public class TcpClient extends Thread {  
   
    public static String HOST = "168.168.1.121";  
    public static int PORT = 9999;  
    
    public void run() {  
    	super.run();
    	
    	EventLoopGroup group = new NioEventLoopGroup();
        try {
            Bootstrap bootstrap  = new Bootstrap()
                    .group(group)
                    .channel(NioSocketChannel.class)
                    .handler(new SimpleChatClientInitializer());
            Channel channel = bootstrap.connect(HOST, PORT).sync().channel();
            while(true){
                channel.writeAndFlush("this msg  test come from client"   "\r\n");
                Thread.currentThread();
				Thread.sleep(1000);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            group.shutdownGracefully();
        }
    }  
}  

资源下载此资源下载价格为3D币(VIP免费),请先
资源文件列表
AndroidNetty.rar , 6982024
JavaNettyProj4.rar , 8253
没有账号? 忘记密码?

社交账号快速登录