我今天從大學獲得了這個示例代碼,它在大學裏面工作得很好,但是當我在家用機器上運行它(使用Eclipse)時,我獲得了權限被拒絕的權限。大學的機器是Windows(7),我家裏的電腦是Linux(Ubuntu)。爲什麼我的權限被拒絕連接到338端口?
爲什麼我會收到以下錯誤?
錯誤I/O 權限被拒絕
我使用端口338
複製代碼:1024下
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);
}
}
}
你在哪裏運行它得到消息(例外,作爲服務器的答案)?你正在使用哪個端口? – SJuan76
什麼錯誤?哪裏? –
哪個端口?哪個操作系統在大學/在家? –