iOS Java SocketException

时间:2012-05-06 06:00:42

标签: java ios post jvm socketexception

我正在iOS上运行JVM。

当我尝试使用来自网页的POST请求获取数据,并且无法建立连接(客户端)时,我收到以下错误:

java.net.SocketException: Invalid argument
  at gnu.java.nio.VMChannel.getpeername(Native Method)
  at gnu.java.nio.VMChannel.getPeerAddress(VMChannel.java:471)
  at gnu.java.nio.SocketChannelImpl.isConnected(SocketChannelImpl.java:194)
  at gnu.java.nio.SocketChannelImpl.read(SocketChannelImpl.java:216)
  at org.apache.mina.transport.socket.nio.SocketIoProcessor.read(SocketIoProcessor.java:218)
  at org.apache.mina.transport.socket.nio.SocketIoProcessor.process(SocketIoProcessor.java:198)
  at org.apache.mina.transport.socket.nio.SocketIoProcessor.access$400(SocketIoProcessor.java:45)
  at org.apache.mina.transport.socket.nio.SocketIoProcessor$Worker.run(SocketIoProcessor.java:485)
  at org.apache.mina.util.NamePreservingRunnable.run(NamePreservingRunnable.java:51)
  at java.lang.Thread.run(Thread.java:743)

我用来执行post请求的代码(注意数据可能是空字符串):

URL url = new URL(urlstring);
URLConnection conn = url.openConnection();
conn.setDoOutput(true);
OutputStreamWriter wr = new OutputStreamWriter(conn.getOutputStream());
wr.write(data);
wr.flush();

// Get the response
BufferedReader rd = new BufferedReader(new InputStreamReader(conn
     .getInputStream()));

此请求也在单独的工作线程中执行。发生这种情况时,程序的其他功能不受影响。

我认为它与正在运行的JVM有关。知道为什么会抛出这个错误吗?你怎么会阻止它出现?

谢谢

0 个答案:

没有答案