尝试通过使用JAVA创建一个电子邮件客户端服务器,我已经实现了以下但是被困在哪里去了...感谢帮助
我正在尝试创建套接字并设置输入和输出流。我们接受用户的请求,调用适当的方法(doSend或doRead),关闭链接,然后询问用户是否想要进行另一次读/发。
Email.java:
import java.io.*;
import java.net.*;
import java.util.*;
public class Email {
private static InetAddress host;
private static final int PORT = 21;
private static String name;
private static Scanner networkInput, userEntry;
private static PrintWriter networkOutput;
public static void main(String[] args) throws IOException {
try {
host = InetAddress.getLocalHost();
} catch (UnknownHostException uhEx) {
System.out.println("Host ID not found!");
System.exit(1);
}
userEntry = new Scanner(System.in);
do {
System.out.print("\nEnter name ('Mike' or 'Jack'): ");
name = userEntry.nextLine();
} while (!name.equals("Mike") && !name.equals("Jack"));
talkToServer();
}
private static void talkToServer() throws IOException {
String option, message, response;
do {
/*******************************************************
* I am trying to cREATE A SOCKET and SET UP the INPUT and the OUTPUT
* STREAMS. We Take USER'S REQUEST, CALL UP THE APPROPRIATE METHOD
* (doSend or doRead), CLOSE THE LINK AND THEN ASK IF USER WANTS TO DO
* ANOTHER READ/SEND.
*******************************************************/
} while (!option.equals("n"));
}
private static void doSend() {
System.out.println("\nEnter 1-line message: ");
String message = userEntry.nextLine();
networkOutput.println(name);
networkOutput.println("send");
networkOutput.println(message);
}
private static void doRead() throws IOException {
/*********************************
* I am trying to full the read method
*********************************/
}
}