最近很多小伙伴都在问为什么会出现“java.net.SocketException:管道损坏”?和java管道破裂这两个问题,那么本篇文章就来给大家详细解答一下,同时本文还将给你拓展ActiveMQ错
最近很多小伙伴都在问为什么会出现“ java.net.SocketException:管道损坏”?和java管道破裂这两个问题,那么本篇文章就来给大家详细解答一下,同时本文还将给你拓展ActiveMQ 错误 java.net.SocketException: Connection reset java.net.SocketException: Connection reset、Android java.net.SocketException:socket failed:EACCES(Permission denied)、Android java.net.SocketException:权限被拒绝、Android:套接字-java.net.SocketException:sendto失败:EPIPE(管道断开)等相关知识,下面开始了哦!
本文目录一览:- 为什么会出现“ java.net.SocketException:管道损坏”?(java管道破裂)
- ActiveMQ 错误 java.net.SocketException: Connection reset java.net.SocketException: Connection reset
- Android java.net.SocketException:socket failed:EACCES(Permission denied)
- Android java.net.SocketException:权限被拒绝
- Android:套接字-java.net.SocketException:sendto失败:EPIPE(管道断开)
为什么会出现“ java.net.SocketException:管道损坏”?(java管道破裂)
我写了一个简单的套接字程序,它工作正常,但是我的朋友使用端口扫描工具,当它扫描到我正在使用的端口时,它会收到“
java.net.SocketException:Broken pipe”错误,发生了什么?以及如何解决?
providerSocket = new ServerSocket(portNum);
connection = providerSocket.accept();
if (connection.getOutputStream() != null) {
//this line crash!!!
out = new ObjectOutputStream(connection.getOutputStream());
out.flush();
}
控制台的详细信息错误:
java.net.SocketException: Broken pipe
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
at java.net.SocketOutputStream.write(SocketOutputStream.java:136)
at java.io.ObjectOutputStream$BlockDataOutputStream.drain(ObjectOutputStream.java:1847)
at java.io.ObjectOutputStream$BlockDataOutputStream.setBlockDataMode(ObjectOutputStream.java:1756)
at java.io.ObjectOutputStream.<init>(ObjectOutputStream.java:230)
ActiveMQ 错误 java.net.SocketException: Connection reset java.net.SocketException: Connection reset
最近在研究 ActiveMQ 控制台报 错误 java.net.SocketException: Connection reset java.net.SocketException: Connection reset, 客户端无法发送消息,客户端是使用Spring结合来做的,请问这个问题何解决?Android java.net.SocketException:socket failed:EACCES(Permission denied)
这里代码MainActivity:
public class MainActivity extends Activity { private UdpClientServer cu; private EditText textIpScheda; private EditText textUdpPort; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); textIpScheda = (EditText) findViewById(R.id.textIpScheda); textUdpPort = (EditText) findViewById(R.id.textUdpPort); try { cu = new UdpClientServer(this); } catch (IOException e) { e.printstacktrace(); } } public EditText getTextIpScheda(){ return textIpScheda; } public void setTextIpScheda(EditText textIpScheda){ this.textIpScheda = textIpScheda; } public EditText getTextUdpPort() { return textUdpPort; } public void setTextUdpPort(EditText textUdpPort) { this.textUdpPort = textUdpPort; }
这里代码UdpClientServer:
public class UdpClientServer { public static String sReceive; private static DatagramSocket dSocket; int receiveBufferSize = 1024; int portUdp = 0; final String PINGACMD = "AT*PINGA001"; InetAddress ipScheda; byte[] receiveData = new byte[receiveBufferSize]; private MainActivity gui = null; public UdpClientServer(MainActivity gui) throws SocketException,IOException { this.gui = gui; portUdp = Integer.parseInt(String.valueOf(gui.getTextUdpPort().getText())); dSocket = new DatagramSocket(portUdp); } public void run(){ while (true) { // svuotamento buffer Arrays.fill(receiveData,(byte) 0); DatagramPacket receivePacket = new DatagramPacket(receiveData,receiveData.length); try { dSocket.receive(receivePacket); } catch (IOException e) { e.printstacktrace(); } ipScheda = receivePacket.getAddress(); int port = receivePacket.getPort(); gui.getTextUdpPort().setText("" + port); gui.getTextIpScheda().setText(ipScheda.getHostAddress()); sReceive = new String(receivePacket.getData()); this.sendCommand(PINGACMD); } } public void sendCommand(String outSentence){ byte[] sendData = outSentence.getBytes(); DatagramPacket sendPacket = new DatagramPacket(sendData,sendData.length,ipScheda,portUdp); try { dSocket.send(sendPacket); Thread.sleep(100); } catch (IOException e) { e.printstacktrace(); } catch (InterruptedException e) { e.printstacktrace(); } finally { } }
}
这里的logcat:
12-29 11:43:22.291 28914-28914/com.example.matteo.myfirstapp W/System.err﹕ java.net.socketException: socket Failed: EACCES (Permission denied) 12-29 11:43:22.294 28914-28914/com.example.matteo.myfirstapp W/System.err﹕ at libcore.io.IoBridge.socket(IoBridge.java:623) 12-29 11:43:22.294 28914-28914/com.example.matteo.myfirstapp W/System.err﹕ at java.net.PlainDatagramSocketImpl.create(PlainDatagramSocketImpl.java:93) 12-29 11:43:22.294 28914-28914/com.example.matteo.myfirstapp W/System.err﹕ at java.net.DatagramSocket.createSocket(DatagramSocket.java:157) 12-29 11:43:22.294 28914-28914/com.example.matteo.myfirstapp W/System.err﹕ at java.net.DatagramSocket.<init>(DatagramSocket.java:80) 12-29 11:43:22.294 28914-28914/com.example.matteo.myfirstapp W/System.err﹕ at com.example.matteo.myfirstapp.UdpClientServer.<init>(UdpClientServer.java:32) 12-29 11:43:22.294 28914-28914/com.example.matteo.myfirstapp W/System.err﹕ at com.example.matteo.myfirstapp.MainActivity.onCreate(MainActivity.java:24) 12-29 11:43:22.294 28914-28914/com.example.matteo.myfirstapp W/System.err﹕ at android.app.Activity.performCreate(Activity.java:5933) 12-29 11:43:22.294 28914-28914/com.example.matteo.myfirstapp W/System.err﹕ at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1105) 12-29 11:43:22.294 28914-28914/com.example.matteo.myfirstapp W/System.err﹕ at android.app.ActivityThread.performlaunchActivity(ActivityThread.java:2251) 12-29 11:43:22.294 28914-28914/com.example.matteo.myfirstapp W/System.err﹕ at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2360) 12-29 11:43:22.294 28914-28914/com.example.matteo.myfirstapp W/System.err﹕ at android.app.ActivityThread.access$800(ActivityThread.java:144) 12-29 11:43:22.294 28914-28914/com.example.matteo.myfirstapp W/System.err﹕ at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1278) 12-29 11:43:22.294 28914-28914/com.example.matteo.myfirstapp W/System.err﹕ at android.os.Handler.dispatchMessage(Handler.java:102) 12-29 11:43:22.294 28914-28914/com.example.matteo.myfirstapp W/System.err﹕ at android.os.Looper.loop(Looper.java:135) 12-29 11:43:22.294 28914-28914/com.example.matteo.myfirstapp W/System.err﹕ at android.app.ActivityThread.main(ActivityThread.java:5221) 12-29 11:43:22.294 28914-28914/com.example.matteo.myfirstapp W/System.err﹕ at java.lang.reflect.Method.invoke(Native Method) 12-29 11:43:22.294 28914-28914/com.example.matteo.myfirstapp W/System.err﹕ at java.lang.reflect.Method.invoke(Method.java:372) 12-29 11:43:22.294 28914-28914/com.example.matteo.myfirstapp W/System.err﹕ at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899) 12-29 11:43:22.294 28914-28914/com.example.matteo.myfirstapp W/System.err﹕ at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694) 12-29 11:43:22.294 28914-28914/com.example.matteo.myfirstapp W/System.err﹕ Caused by: android.system.ErrnoException: socket Failed: EACCES (Permission denied) 12-29 11:43:22.294 28914-28914/com.example.matteo.myfirstapp W/System.err﹕ at libcore.io.Posix.socket(Native Method) 12-29 11:43:22.294 28914-28914/com.example.matteo.myfirstapp W/System.err﹕ at libcore.io.BlockGuardOs.socket(BlockGuardOs.java:282) 12-29 11:43:22.294 28914-28914/com.example.matteo.myfirstapp W/System.err﹕ at libcore.io.IoBridge.socket(IoBridge.java:608) 12-29 11:43:22.294 28914-28914/com.example.matteo.myfirstapp W/System.err﹕ ... 18 more
在我的AndroidManifest.xml中刚刚添加了字符串
<uses-permission android:name="android.permission.INTERNET"/>
但它不行
你可以帮我吗?
谢谢
解决方法
<uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
Android java.net.SocketException:权限被拒绝
如何解决Android java.net.SocketException:权限被拒绝?
我是一名Android初学者。 我想创建一个ServerSocket,但是它总是在“ serverSocket = new ServerSocket(12345);”行上调用“ java.net.socketException:权限被拒绝”。 我想知道为什么,谢谢。
ServerThread.java
public class ServerThread extends Thread {
ServerSocket serverSocket ;
@Override
public void run() {
try {
serverSocket = new ServerSocket(12345);
while(true) {
System.out.println("IN");
Socket socket = serverSocket.accept(); // null
}
} catch (IOException e) {
e.printstacktrace();
}
}
}
MainActivity.java
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
new ServerThread().start();
}
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)
Android:套接字-java.net.SocketException:sendto失败:EPIPE(管道断开)
我正在尝试使用套接字与服务器建立连接。连接管道损坏,如下所示。
01-31 14:47:16.536: W/System.err(27255): java.net.SocketException: sendto failed: EPIPE (Broken pipe)
01-31 14:47:16.550: W/System.err(27255): at libcore.io.IoBridge.maybeThrowAfterSendto(IoBridge.java:496)
01-31 14:47:16.550: W/System.err(27255): at libcore.io.IoBridge.sendto(IoBridge.java:465)
01-31 14:47:16.550: W/System.err(27255): at java.net.PlainSocketImpl.write(PlainSocketImpl.java:507)
01-31 14:47:16.550: W/System.err(27255): at java.net.PlainSocketImpl.access$100(PlainSocketImpl.java:46)
01-31 14:47:16.664: W/NetworkManagementSocketTagger(24437): setKernelCountSet(10021,1) failed with errno -2
01-31 14:47:16.684: W/System.err(27255): at java.net.PlainSocketImpl$PlainSocketOutputStream.write(PlainSocketImpl.java:269)
01-31 14:47:16.693: W/System.err(27255): at java.io.DataOutputStream.write(DataOutputStream.java:98)
01-31 14:47:16.693: W/System.err(27255): at java.io.OutputStream.write(OutputStream.java:82)
01-31 14:47:16.693: W/System.err(27255): at com.x.x.y.sendRec(y.java:460)
01-31 14:47:16.693: W/System.err(27255): at com.x.x.y.access$0(y.java:384)
01-31 14:47:16.693: W/System.err(27255): at com.x.x.y$2.run(y.java:363)
01-31 14:47:16.693: W/System.err(27255): at java.lang.Thread.run(Thread.java:856)
01-31 14:47:16.693: W/System.err(27255): Caused by: libcore.io.ErrnoException: sendto failed: EPIPE (Broken pipe)
01-31 14:47:16.693: W/System.err(27255): at libcore.io.Posix.sendtoBytes(Native Method)
01-31 14:47:16.693: W/System.err(27255): at libcore.io.Posix.sendto(Posix.java:146)
01-31 14:47:16.693: W/System.err(27255): at libcore.io.BlockGuardOs.sendto(BlockGuardOs.java:177)
01-31 14:47:16.693: W/System.err(27255): at libcore.io.IoBridge.sendto(IoBridge.java:463)
这是代码,在此行上outStreamRec.write(bData);
引发异常。
try {
port = 86;
byterecv = new byte[1040];
clientRec = new Socket();
clientRec.connect(new InetSocketAddress("192.168.1.36",port));
System.out.println("Just connected to " + clientRec.getRemoteSocketAddress());
} catch (IOException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
while (true) {
try {
System.out.println("Connecting to " + ServerUrl.url + " on port " + port);
OutputStream outToServerRec = clientRec.getOutputStream();
DataOutputStream outStreamRec = new DataOutputStream(outToServerRec);
outStreamRec.write(bData);
InputStream inFromServerPlay = clientRec.getInputStream();
DataInputStream inStreamPlay = new DataInputStream(inFromServerPlay);
while ((lstream = inStreamPlay.read(byterecv)) != -1) {
System.out.println("startrec bytearray -- " + byterecv.length);
bos1.write(byterecv,lstream);
}
if (stopcall == true) {
clientRec.close();
break;
}
} catch (IOException e) {
e.printStackTrace();
}
}
注意:如果我关闭套接字连接,立即可以正常工作。但是我想保持连接仍然活跃,所以我手动关闭套接字连接。停止按钮的onclick我正在关闭连接。
我在网上搜索,但没有找到解决此问题的方法。
我们今天的关于为什么会出现“ java.net.SocketException:管道损坏”?和java管道破裂的分享已经告一段落,感谢您的关注,如果您想了解更多关于ActiveMQ 错误 java.net.SocketException: Connection reset java.net.SocketException: Connection reset、Android java.net.SocketException:socket failed:EACCES(Permission denied)、Android java.net.SocketException:权限被拒绝、Android:套接字-java.net.SocketException:sendto失败:EPIPE(管道断开)的相关信息,请在本站查询。
本文标签: