我得到java.net.SocketTimeoutException:当我使用以下代码发送GET请求时,传输端点未连接异常.此代码适用于其他GET请求,但不适用于某个特定URL.知道我可能做错了什么吗?
try {
URL mUrl = new URL(url);
urlConn = (HttpURLConnection) mUrl.openConnection();
urlConn.setReadTimeout(5000);
urlConn.setConnectTimeout(5000);
urlConn.setRequestMethod(requestMethod);
if (contentType != null)
urlConn.addRequestProperty("Content-Type", "application/"
+ contentType);
urlConn.setDoOutput(true);
if (query != null) {
urlConn.setRequestProperty("Content-Length",
Integer.toString(query.length()));
urlConn.getOutputStream().write(query.getBytes("UTF8"));
}
urlConn.connect();
if (urlConn.getResponseCode() == HttpURLConnection.HTTP_OK) {
StringBuffer responseMsg = new StringBuffer();
InputStream dis = urlConn.getInputStream();
int chr;
while ((chr = dis.read()) != -1) {
responseMsg.append((char) chr);
}
return new Response(urlConn.getResponseCode(),
urlConn.getResponseMessage(),
responseMsg.toString());
}
return new Response(urlConn.getResponseCode(),
urlConn.getResponseMessage(), null);
} catch (IOException e) {
throw e;
} finally …Run Code Online (Sandbox Code Playgroud) 我们是一个Struts2 java webapplication,使用hibernate 3.5 ORM.当我们在应用程序上执行一些并行操作时,我们得到以下异常,并且java进程cpu利用率处于最大值.
May 15, 2012 12:39:59 AM org.apache.catalina.core.ApplicationDispatcher invoke
SEVERE: Servlet.service() for servlet jsp threw exception
java.net.SocketException: Too many open files
at java.net.PlainSocketImpl.socketAccept(Native Method)
at java.net.PlainSocketImpl.accept(PlainSocketImpl.java:408)
at java.net.ServerSocket.implAccept(ServerSocket.java:462)
at java.net.ServerSocket.accept(ServerSocket.java:430)
at org.apache.tomcat.util.net.DefaultServerSocketFactory.acceptSocket(DefaultServerSocketFactory.java:59)
at org.apache.tomcat.util.net.JIoEndpoint$Acceptor.run(JIoEndpoint.java:210)
at java.lang.Thread.run(Thread.java:662)
Run Code Online (Sandbox Code Playgroud)
请相应地建议我们.
我是C#的新手,我正在尝试使用C#访问SFTP(从Internet获取一些代码).我通过编写下面的代码尝试了这个.但我得到例外:
IPHostEntry hostInfo = Dns.GetHostByName(@"sftp://........");
// Get the IP address list that resolves to the host names contained in the
// Alias property.
IPAddress[] address = hostInfo.AddressList;
// Get the alias names of the addresses in the IP address list.
Run Code Online (Sandbox Code Playgroud)
"捕获了SocketException:请求的名称有效,但未找到所请求类型的数据"
我发现了很多关于这一点,但没有理解.此外,我尝试使用Tamir.SharpSSH库连接SFTP,但获得相同的异常.
请建议一些解决方案.我的项目需要这个.
谢谢
我尝试从 Android 项目中的 URL 读取 json 文件。但奇怪的情况发生了。StringBuilder 成功获取前几个字符,但随后我得到 java.net.SocketException: recvfrom failed: EBADF (Bad file detector)
为什么我会得到这个异常?
我的代码有什么问题吗?)
JSON: http: //inlyfortesting.ucoz.net/artists.json
我的 JSON 解析器:
public JSONArray getJSONFromUrl(String urlAsString) {
// try to create JSONObject from string
try {
URL url = new URL(urlAsString);
new DownloadFileTask().execute(url).get();
jObj = new JSONArray(json);
} catch (JSONException e) {
Log.e("JSON Parser", "Error parsing data " + e.toString());
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
} …Run Code Online (Sandbox Code Playgroud) 当我尝试解析字符串形式的IP地址时,我收到此错误.
我在测试时使用了公共dns ip地址(4.2.2.2)(使用System.Net的IPAddress.Parse方法).
它正确解析并返回一个IPAddress对象.但是,如果我尝试访问此对象的ScopeId属性,则抛出SocketException,并在标题中给出消息.
我真的无法弄清楚这里的问题是什么.当我检查IPAddress.ScopeId属性的文档时,它说当AddressFamily = InterNetwork时会抛出异常,这就是我的例子.
有人可以解释一下这个原因.
我的代码如下.当请求到来时,服务器创建两个线程(生产者 - 消费者模式):
...
while(true) {
Socket clientSocket = server.accept();
System.out.println("Got connection!");
Thread consumerThread = new Thread(new ConsumerThread(sharedQueue, clientSocket));
Thread producerThread = new Thread(new ProducerThread(sharedQueue, clientSocket));
consumerThread.start();
producerThread.start();
}
...
Run Code Online (Sandbox Code Playgroud)
消费者线程读取客户端发送的内容和生产者线程的响应.消费者:
@Override
public void run() {
try {
while (true) {
in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
// read, do actions
}
} catch (IOException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
} finally {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
Run Code Online (Sandbox Code Playgroud)
制片人:
@Override …Run Code Online (Sandbox Code Playgroud) 我有一个循环打开一个套接字,作用于套接字,然后关闭套接字并重新启动.但是,在我得到的第二次迭代中SocketException,通常只允许使用每个套接字地址(协议/网络地址/端口).
但是,套接字应该关闭,netstat -a并不表示我正在侦听该端口或任何东西.抛出异常的代码是:
_bindedLocalSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
_bindedLocalSocket.Bind(new IPEndPoint(Util.ChannelProfileToListeningAddress(_profile), _profile.ListenPort));
_bindedLocalSocket.Listen(30);
_bindedLocalSocket.BeginAccept(new AsyncCallback(OnRequested), null);
Run Code Online (Sandbox Code Playgroud)
但是,我认为罪魁祸首不是代码,就在我开始使用该代码之前,在我尝试关闭连接之前,我得到了这个:
An existing connection was forcibly closed by the remote host at System.Net.Sockets.Socket.EndReceive(IAsyncResult asyncResult) at Poderosa.PortForwarding.SynchronizedSocket.EndReceive(IAsyncResult ar) at Poderosa.PortForwarding.Channel.OnSocketData(IAsyncResult result)
一旦我关闭程序并再次运行它,它可以使第一个连接正常,第二个连接正常(SocketException).有谁知道如何解决这个问题?
我正在开发Android 2.2和LG Black设备的应用程序.当我在我的LG设备上运行应用程序时,我得到以下SocketException,这在其他设备上永远不会发生!
Broken pipe
java.net.SocketException: Broken pipe
at org.apache.harmony.luni.platform.OSNetworkSystem.writeSocketImpl(Native Method)
at org.apache.harmony.luni.platform.OSNetworkSystem.write(OSNetworkSystem.java:723)
at org.apache.harmony.luni.net.PlainSocketImpl.write(PlainSocketImpl.java:578)
at org.apache.harmony.luni.net.SocketOutputStream.write(SocketOutputStream.java:59)
Run Code Online (Sandbox Code Playgroud)
如何解决?谢谢.
我正在尝试从另一个类调用一个方法,这意味着我想使用序列化我创建方法名称的对象和它的参数并将其写在套接字上,但是当我想创建ObjectOutputStream时遇到错误"由同行重置连接:套接字写入错误"我搜索了可能的原因,但我找不到任何合适的答案
在服务器端我没有关闭套接字或我没有做任何工作关闭,我不知道会发生什么: - ??
在线:
ObjectOutputStream oos = (new ObjectOutputStream(os));
Run Code Online (Sandbox Code Playgroud)
我的代码是这样的:
InvocationVO invo = new InvocationVO("showStart", treasure, round);
for (int i = 0; i < numPlayer; i++) {
OutputStream os = socket.get(i).getOutputStream();
ObjectOutputStream oos = (new ObjectOutputStream(os)); // this has error
oos.writeObject(invo);
oos.close();
os.close();
Client.getClients()[i].invoke();
}
Run Code Online (Sandbox Code Playgroud)
感谢您的帮助!
java.net.SocketException: Connection reset by peer: socket write error
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(Unknown Source)
at java.net.SocketOutputStream.write(Unknown Source)
at java.io.DataOutputStream.write(Unknown Source)
at java.io.DataOutputStream.writeUTF(Unknown Source)
at java.io.DataOutputStream.writeUTF(Unknown Source)
at SignUp.setUser(SignUp.java:225)
at SignUp.jButton1_actionPerformed(SignUp.java:207)
at SignUp.access$3(SignUp.java:201)
at SignUp$4.actionPerformed(SignUp.java:135)
at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
at java.awt.Component.processMouseEvent(Unknown Source)
at javax.swing.JComponent.processMouseEvent(Unknown Source)
at java.awt.Component.processEvent(Unknown Source)
at java.awt.Container.processEvent(Unknown Source)
at java.awt.Component.dispatchEventImpl(Unknown Source)
at java.awt.Container.dispatchEventImpl(Unknown Source)
at java.awt.Component.dispatchEvent(Unknown Source)
at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
at …Run Code Online (Sandbox Code Playgroud) 我正在尝试制作一个基本的客户端/服务器程序,但是当我启动 TcpListener 时,它给了我SocketException:The requested address is not valid in its context.
实际上有一个返回我的公共 IP 的方法,并且它与 ipconfig 结果匹配,因此下面的 IP 地址字符串不能是问题。当然,出于安全原因,下面显示的 IP 不是我的真实 IP。我打开了下面的端口供一般使用。
无论如何,Not valid in context很模糊,所以我不确定这意味着什么。
这是我的代码(对于 TcpListener):
ServerIn = new TcpListener(IpAddress.Parse("100.100.100.100"), 8000);
ServerIn.Start();
Run Code Online (Sandbox Code Playgroud)
提前致谢。
socketexception ×11
c# ×4
java ×4
android ×3
sockets ×3
.net-3.5 ×1
broken-pipe ×1
ip-address ×1
java-ee ×1
json ×1
lg ×1
networking ×1
sftp ×1
struts2 ×1
system.net ×1
tcp ×1
url ×1