当我尝试启动我的 doinbackground 以等待传入的消息时,它从未真正运行过它只是跳过它
public class Incomingdata extends AsyncTask<Void,Void,Void>
{
Socket s ;
String input;
public Incomingdata(Socket socket)
{
super();
this.s = socket;
}
@Override
protected Void doInBackground(Void... params)
{
Log.i("ddd","Got here before try");
try
{
InputStream in = s.getInputStream();
Scanner r = new Scanner(in);
Log.i("Info",s.getPort()+"");
Log.i("ddd","Got here");
while(s.isConnected() && r.hasNext())
{
String input =r.nextLine();
}
}
catch (UnknownHostException e)
{
e.printStackTrace();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
catch(NoSuchElementException e)
{
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void input)
{
System.out.println("123"+input);
}
}
这是我的原木猫
java.net.Socket.startupSocket(Socket.java:724)
04-25 23:50:26.659: W/System.err(28882): at java.net.Socket.<init>(Socket.java:263)
04-25 23:50:26.659: W/System.err(28882): at com.example.handy.myComs.sending_data(myComs.java:23)
04-25 23:50:26.659: W/System.err(28882): at com.example.handy.MainActivity.readSms(MainActivity.java:277)
04-25 23:50:26.659: W/System.err(28882): at com.example.handy.MainActivity$1.onClick(MainActivity.java:92)
04-25 23:50:26.659: W/System.err(28882): at android.view.View.performClick(View.java:2485)
04-25 23:50:26.659: W/System.err(28882): at android.view.View$PerformClick.run(View.java:9080)
04-25 23:50:26.659: W/System.err(28882): at android.os.Handler.handleCallback(Handler.java:587)
04-25 23:50:26.659: W/System.err(28882): at android.os.Handler.dispatchMessage(Handler.java:92)
04-25 23:50:26.659: W/System.err(28882): at android.os.Looper.loop(Looper.java:130)
04-25 23:50:26.659: W/System.err(28882): at android.app.ActivityThread.main(ActivityThread.java:3687)
04-25 23:50:26.659: W/System.err(28882): at java.lang.reflect.Method.invokeNative(Native Method)
04-25 23:50:26.659: W/System.err(28882): at java.lang.reflect.Method.invoke(Method.java:507)
04-25 23:50:26.659: W/System.err(28882): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
04-25 23:50:26.659: W/System.err(28882): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
04-25 23:50:26.659: W/System.err(28882): at dalvik.system.NativeStart.main(Native Method)
04-25 23:50:26.729: I/System.out(28882): 123null
这就是我所说的
public class myComs
{
private static int i = 0;
public static void sending_data(String ipAddress, String message)
{
try
{
InetAddress inet = InetAddress.getByName(ipAddress);
Socket s = new Socket(inet, 2000);
OutputStream o = s.getOutputStream();
PrintWriter p = new PrintWriter(o);
while(i<1)
{
new Incomingdata(s).execute();
i++;
}
p.println(message);
p.flush();
}
catch (UnknownHostException e)
{
e.printStackTrace();
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
正如您在 123null 中看到的那样,它永远不会等待任何帮助,因为我在这方面已经很长时间了,而且速度很快
谢谢
更新 是的,我通过并知道它正在获取端口,但它仍然没有等待传入数据它刚刚完成