저는 현재 안드로이드 용 게임을 개발 중입니다. 이 게임에는 무거운 네트워킹이 있습니다.좋은 안드로이드 네트워크 실습
하나는 메시지를 수신하고 다른 하나는 메시지를 보내는 두 개의 분리 된 스레드를 갖는 것이 좋습니다. 또는 메시지 송수신을위한 단일 스레드를 갖는 것이 더 나은가?
public static void init(String h){
host=h;
connected=false;
instance = new Client();
new Thread(new Runnable() {
@Override
public void run() {
group = new NioEventLoopGroup();
try{
bootstrap = new Bootstrap()
.group(group)
.channel(NioSocketChannel.class)
.handler(instance);
channel = bootstrap.connect(host,PORT).sync().channel();
connected=true;
} catch (Exception e) {
if (notifier!=null){
notifier.onServerNoLongerReachable();
}
e.printStackTrace();
}
}
}).start();
}
public static void setNotifier(ClientInterface notif){
notifier = notif;
}
나는 인 Netty를 사용하고 있는데 내 활동이 스레드를 사용하여 안드로이드 개발자를위한 좋은 방법이 아닙니다
public interface ClientInterface{
void onReceive(String msg);
void onServerNoLongerReachable();
}
하나의 스레드가 이상적 일 것이다 : 당신은 RxJava 승/개조를 사용할 수, networkCall를 들어 https://github.com/ReactiveX/RxAndroid
: https://developer.android.com/guide/components/processes-and-threads.html
또는 Cricket_007대로 RxJava을 살펴해야합니다 사용 AsyncTask를 더 낫다 현재이 질문을하기 위해 어떤 문제가 발생하고 있습니까? 그리고 네트워크 요청을 돕기 때문에'RxJava'를 사용하고 있습니까? –
현재 문제가 발생하지 않고 있습니다. 잘못 입력하지 않았 음을 확인하는 중입니다. – logan20
예제로 모든 코드를 제공 할 수 있습니까? –