简体   繁体   English

套接字创建超时

[英]Socket creation times out

I'm working on an assignment for my Distributed Computing course, which deals with basic sockets and I'm having a bit of a problem. 我正在为“分布式计算”课程的一项作业做作业,该课程处理基本套接字,但我遇到了一些问题。 My code executes and runs properly via SSH on university computers but from my laptop it doesn't. 我的代码可以通过SSH在大学计算机上执行并正常运行,但是在我的笔记本电脑上却无法。

I have a server java file that is running on a university computer via SSH. 我有一个通过SSH在大学计算机上运行的服务器java文件。 If I start another SSH session and run my code from that computer everything runs smoothly. 如果我启动另一个SSH会话并从那台计算机上运行我的代码,那么一切将顺利运行。 However, if I execute that code off of my local machine I get a Socket Timed Out error. 但是,如果我在本地计算机上执行该代码,则会收到套接字超时错误。

Here's the code for the Client file, which throws the error: 这是客户端文件的代码,它引发错误:

try {
    addr = InetAddress.getByName("___IP_Here____");
    sock = new Socket(addr,3165);
} catch (Exception e) {
    System.err.println("Creating Socket failed.");
    System.out.println(e);
    System.exit(1);
}

Here's the Server code for creating the server: 这是用于创建服务器的服务器代码:

try {
    addr = InetAddress.getLocalHost();
    sock = new ServerSocket(3165,3,addr);
} catch (Exception e) {
    System.err.println("Creating ServerSocket failed.");
    System.out.println(e);
    System.exit(1);
}

I thought that it might be a problem with the Firewall and I added exceptions to allow Java in both inbound and outbound. 我认为这可能是防火墙的问题,我添加了例外,以允许Java入站和出站。 Does anyone have an idea of what could possibly be wrong? 有谁知道什么可能是错的?

EDIT: The server socket has a timeout of 0, which is infinity. 编辑:服务器套接字的超时为0,这是无穷大。 http://download.java.net/jdk7/archive/b123/docs/api/java/net/ServerSocket.html#getSoTimeout() http://download.java.net/jdk7/archive/b123/docs/api/java/net/ServerSocket.html#getSoTimeout()

EDIT: This is actually a university security issue. 编辑:这实际上是大学的安全问题。

Firewall might be your problem. 防火墙可能是您的问题。 Allowing java might be not enough, check for ports and rules with higher priority. 仅允许java可能不够,请检查优先级较高的端口和规则。 If you are in a safe environment, or disconnected you might try to turn it off to confirm if it is the firewall or not. 如果您处于安全环境中或已断开连接,则可以尝试将其关闭以确认是否为防火墙。 BTW, close your resources or consider using try-with-resources instead of simple try and catch, this other thing to look for, try to kill your process and check if you can connect. 顺便说一句,关闭您的资源或考虑使用try-with-resources而不是简单的try and catch,这是另一件要寻找的事情,尝试终止您的进程并检查是否可以连接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM