0
나는 안드로이드에서 로컬 호스트 서버를 만들었고 내 아약스 호출과 통신하려고합니다. 서버에 성공적으로 연결되었지만 response.xmlhttp 상태를 수신 할 수 없으면 0 만 반환됩니다. 서버를 생성했습니다. SEPA 법으로android에서 로컬 호스트 서버
아약스 전화
function loadXMLDoc()
{
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
document.getElementById("myDiv3").innerHTML=xmlhttp.readyState+"";
// document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
if (xmlhttp.readyState==4)
{
document.getElementById("myDiv1").innerHTML=xmlhttp.status+"";
document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
}
// document.getElementById("myDiv2").innerHTML="2";
}
xmlhttp.open("GET","http://localhost:8888/Server",true);
//xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
xmlhttp.send();
}
서버 코드
try{
String fromclient;
String toclient;
ServerSocket Server = new ServerSocket (8888);
System.out.println ("TCPServer Waiting for client on port 8888");
while(true)
{
Socket connected = Server.accept();
System.out.println(" THE CLIENT"+" "+
connected.getInetAddress() +":"+connected.getPort()+" IS CONNECTED ");
PrintWriter outToClient =
new PrintWriter(
connected.getOutputStream(),true);
outToClient.write("<html><head>hai</head></html>");
connected.close();
}
}
catch(Exception e)
{
}
}