2013-06-29 4 views
0

android xfire 클라이언트에서 연결을 설정하려고합니다. TCP 연결입니다. 나는 어디에서나 인터넷 검색을 해왔고 xfire (메시징 서비스)에 연결하기 위해 포트 25999에서 cs.xfire.com을 반복해서 사용했다. 하지만 결국 나는 예외가 있다고 말합니다. 그래서 왜 내가 연결을 설정할 수 없는지 알고 싶습니다. 인터넷에 연결되지 않는 이유를 알아내는 데 도움이되는 정보가 거의 없습니다. 패킷 스니퍼를 통해 연결을 청취했으며 공식 xfire에서 "연결"을 클릭하면 포트 25999를 받았습니다. Windows 응용 프로그램. 그래서이 질문은 많은 감각을하지 않을 경우, 여기에 내가 무슨의 코드는 정말 혼란 죄송 :java.net.UnknownHostException : cs.xfire.com

public class Connectionn extends Activity{ 
private DataInputStream in = null; 
private DataOutputStream out = null; 
private byte[] buffer; 
private String username, password, nickname, statustext = "Online"; 
private boolean runThread = true; 

protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.connected); 
    TextView txtView1 = (TextView) findViewById(R.id.tvTest); 
    Bundle extras = getIntent().getExtras(); 
    String username = extras.getString("username"); 
    String password = extras.getString("password"); 

    try { 

     Socket s = new Socket("cs.xfire.com", 25999); 
     txtView1.setText("Connected!"); 
     in = new DataInputStream(s.getInputStream()); 
     out = new DataOutputStream(s.getOutputStream()); 
     login(); 
    } catch (IOException ioe) { 
     //disconnect(); 
     txtView1.setText(ioe.toString()); 

    } 
} 

public void run() { 
    setTitle("Xfire Reader Thread"); 
    while(runThread) { 
      readBytes(); 
      debug(buffer); 

      switch(buffer[0] & 0xFF) { 
      case 0x80: // salt 

        break; 
      case 0x81: // auth failed 
        disconnect(); 

        break; 
      case 0x82: // loginreply 


        break; 
      case 0x83: // friendslist 

        break; 
      case 0x84: // friend online 

        break; 
      case 0x85: // receive message 

       /*ReceiveMessagePacket rmp = new ReceiveMessagePacket(buffer); 
        if (rmp.getMessageType() == ReceiveMessagePacket.MSGTYPE_IM) { 
          AckImPacket amp = 
            new AckImPacket(rmp.getSid(), rmp.getImIndex()); 
          write(amp.getBytes()); 
        }*/ 

        break; 
      case 0x87: // friend in game 

        break; 
      case 0x91: // disconnected with reason 
        disconnect(); 

        break; 
      case 0x9a: // friend status text 

        break; 
      case 0xac: 

        break; 
      } 
    } 
} 

private void login() { 
    // TODO Auto-generated method stub 

    // initialize connection with the 'UA01' packet 
    write("UA01".getBytes()); 

    // send the version packet 
    final byte[] p_version_1 = new byte[] { 
      0x03, 0, 0x01, 0x07, 
      0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, // version 
      0x02 
    }; 

    final int version = 118; 
    String vp = null; 
    write(vp.getBytes()); 

    // start the reader thread 
    onStart(); 

} 

public void disconnect() { 
    //EventManager.removeObserver(this); 
    runThread = false; 

    try { 
      out.write(new byte[] { 0, 0, 0, 0 }); // sabotage the stream      
    } catch (IOException ioe) { 
      ioe.printStackTrace(); 
    } finally { 
      try { 
        out.close(); 
        in.close(); 
      } catch (IOException ioe) { 
        ioe.printStackTrace(); 
      } 
      //FriendManager.getInstance().cleanup(); 
      // EventManager.fireEvent(new DatalessEvent(XfireEvent.XF_OFFLINE)); 
    } 
} 

private void readBytes() { 
    try { 
      byte[] numBytes = new byte[2]; 
      in.read(numBytes, 0, 2); 
      int low = numBytes[0] & 0xFF, high = numBytes[1] & 0xFF; 
      int len = (0x00 | low | (high << 8)) - 2; 

      if (len <= 0) { 
        buffer = new byte[] { 0 }; 
        return; 
      } 

      buffer = new byte[len]; 
      in.read(buffer, 0, len); 
    } catch (IOException ioe) { 
      ioe.printStackTrace(); 
      disconnect(); 
    } 
} 

private static void debug(byte[] bs) { 
    for (byte b : bs) { 
      System.out.print(String.format("%02x", b) + " "); 
    } 
    System.out.println(); 
} 

public void write(byte[] bs) { 
    try { 
      out.write(bs); 
    } catch (IOException ioe) { 
      ioe.printStackTrace(); 
      disconnect(); 
    } 
} 
} 

답변

0

내가 그것을 연결하지 말 예외가이

아니야. 다시 읽으십시오. 그것은 당신의 타이틀에 있습니다. 그것은 '알 수없는 호스트'라고합니다. 연결 실패가 아닙니다. 조회 실패입니다. cs.xfire.com이 없거나 귀하의 DNS에 알려지지 않았습니다.

+0

예,하지만 조회 실패 일 수 있습니까? 내 라우터에서 25999 포트를 전달했으며 cs.xfire.com은 존재합니다. – user1953302

+1

@ user1953302 - 그럼에도 불구하고, 메시지는 그것이 검색 오류라고 말하고 있으며 그것에 대해 거짓을 알릴 수있는 상황을 생각하기 어렵습니다. 논리적 근거를 설명하는 견고한 논리를 가지고 있지 않다면, 증거를 기각해서는 안됩니다. –

+0

@ user1953302 - 특정 머신/가상에서 "cs.xfire.com"의 DNS 조회를 시도하여 시작하십시오. 성공하면 JVM에서 DNS 검색 실패의 원인을 찾으십시오. –

관련 문제