Java 为什么我的连接端口338被拒绝?
今天我从大学里得到了这个示例代码,它在大学里运行得很好,但是当我在家里的机器上运行它(使用Eclipse)时,我的权限被拒绝了。大学里的电脑是Windows(7),我家里的电脑是Linux(Ubuntu) 为什么会出现以下错误 I/O错误 拒绝许可 我正在使用端口338 守则副本:Java 为什么我的连接端口338被拒绝?,java,exception,permissions,Java,Exception,Permissions,今天我从大学里得到了这个示例代码,它在大学里运行得很好,但是当我在家里的机器上运行它(使用Eclipse)时,我的权限被拒绝了。大学里的电脑是Windows(7),我家里的电脑是Linux(Ubuntu) 为什么会出现以下错误 I/O错误 拒绝许可 我正在使用端口338 守则副本: import java.io.*; import java.net.*; import java.util.*; public class Server { public static void main
import java.io.*;
import java.net.*;
import java.util.*;
public class Server
{
public static void main(String[] args)
{
try
{
// First create the input from the keyboard
BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Server Program");
// Get the port to listen on
System.out.print("Enter port number to listen on: ");
String port_string = input.readLine();
// The port number needs to be an int, so convert the String to an int
int port = Integer.parseInt(port_string);
// Create a ServerSocket to listen on this address
ServerSocket server = new ServerSocket(port);
// Accept an incoming client connection on the server socket
Socket sock = server.accept();
// Create the output stream to the client
DataOutputStream network = new DataOutputStream(sock.getOutputStream());
// Send message
network.writeUTF("Welcome " + sock.getInetAddress().getHostName() + ". We are " + new Date() + "\n");
// Close sockets. This will cause the client to exit
sock.close();
server.close();
}
catch (IOException ioe)
{
System.err.println("Error in I/O");
System.err.println(ioe.getMessage());
System.exit(-1);
}
}
}
1024以下的端口在大多数现代操作系统(包括Ubuntu)上都具有特权,并且要求您以管理员/root或提升权限运行程序
尝试在家中使用更高的端口进行测试,您应该可以。1024以下的端口在大多数现代操作系统(包括Ubuntu)上都具有特权,并且要求您以管理员/root或提升权限运行程序
尝试在家中使用更高的端口进行测试,您应该可以。您说您的家庭计算机正在运行Ubuntu 在Ubuntu(以及其他类似Unix的操作系统)上,普通用户不允许在端口1024以下的端口上侦听
试着用端口号>=1024运行它。你说你的家庭机器正在运行Ubuntu 在Ubuntu(以及其他类似Unix的操作系统)上,普通用户不允许在端口1024以下的端口上侦听
尝试使用端口号>=1024运行它。从哪里获得消息(异常,作为服务器的答案)?您使用哪个端口?哪个端口?大学/家庭使用哪种操作系统?注意:在类似Unix的操作系统上,只有在拥有根权限的情况下,才能使用小于1024的端口号。请尝试端口号>=1024。可能有多种情况。a) 该端口不在公共范围内,因此可能被占用。另外,b),防火墙可能会阻止端口?您从哪里获得消息(例外,作为对服务器的回答)?您使用哪个端口?哪个端口?大学/家庭使用哪种操作系统?注意:在类似Unix的操作系统上,只有在拥有根权限的情况下,才能使用小于1024的端口号。请尝试端口号>=1024。可能有多种情况。a) 该端口不在公共范围内,因此可能被占用。另外,b),防火墙可能会阻止端口?