Socket Java应用程序-客户端类操作的Html站点
我正在制作一个使用套接字连接的java程序。我编写了一个标准的服务器和客户端应用程序 问题是我必须通过客户端的应用程序登录(通过提供用户名和密码)。当我登录时,我无法打开我的网页,我不知道如何打开 我所说的标准服务器和客户端应用程序是指:Socket Java应用程序-客户端类操作的Html站点,java,sockets,Java,Sockets,我正在制作一个使用套接字连接的java程序。我编写了一个标准的服务器和客户端应用程序 问题是我必须通过客户端的应用程序登录(通过提供用户名和密码)。当我登录时,我无法打开我的网页,我不知道如何打开 我所说的标准服务器和客户端应用程序是指: import java.io.*; import java.net.*; import java.util.*; public class EchoServer { public static void main(String args[]) thr
import java.io.*;
import java.net.*;
import java.util.*;
public class EchoServer {
public static void main(String args[]) throws IOException {
ServerSocket echoServer = null;
Socket clientSocket = null;
BufferedReader in = null;
PrintWriter out = null;
try {
echoServer = new ServerSocket(9999);
}
catch (IOException e) {
System.out.println(e);
System.exit(1);
}
try {
clientSocket = echoServer.accept();
InetAddress address = clientSocket.getInetAddress();
int port = clientSocket.getPort();
in = new BufferedReader(new InputStreamReader(clientSocket.getInputStream()));
out = new PrintWriter(clientSocket.getOutputStream(), true);
String line;
while ((line = in.readLine()) != null) {
out.println(line);
}
in.close();
out.close();
clientSocket.close();
}
catch (IOException e) {
System.out.println(e);
}
echoServer.close();
}
}
客户:
import java.util.*;
import java.net.*;
import java.io.*;
public class EchoClient {
public static void main(String[] args) throws IOException {
Socket echoSocket = null;
PrintWriter out = null;
BufferedReader in = null;
String hostname = "localhost";
if(args.length > 0) hostname=args[0];
try {
echoSocket = new Socket(hostname, 9999);
out = new PrintWriter(echoSocket.getOutputStream(), true);
in = new BufferedReader(new InputStreamReader(echoSocket.getInputStream()));
} catch (UnknownHostException e) {
System.exit(1);
} catch (IOException e) {
System.exit(1);
}
BufferedReader stdIn = new BufferedReader(new InputStreamReader(System.in));
String userInput;
while ((userInput = stdIn.readLine()) != null) {
out.println(userInput);
System.out.println("echo: " + in.readLine());
}
out.close();
in.close();
stdIn.close();
echoSocket.close();
}
}
我知道这段代码不会将html源文件传输到web浏览器,但它会在我的代码中传输
如何在通过客户端服务器连接后将web浏览器连接到服务器?此外,除非我们在这里没有看到一些HTTP位,否则代码中任何地方都不涉及web浏览器…@Charles I在下面写道,这些代码不会将html源文件传输到web浏览器,但在我的代码中会传输。