请问该怎么解决?麻烦哪位高手给我具体答案好吗 因为本人是新手看不懂专业术语
请问该怎么解决?麻烦哪位高手给我具体答案好吗 因为本人是新手看不懂专业术语
不能创建一个新的客户端口
先打开MyEclipse,创建两个类(Client,Server)
package src;
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.net.Socket; import java.net.UnknownHostException;
public class Client {
public static void main(String[] args) throws UnknownHostException, IOException { Socket socket = new Socket("127.0.0.1",6666); BufferedReader bf = new BufferedReader(new InputStreamReader(socket.getInputStream())); System.out.println(bf.readLine()); bf.close(); socket.close(); }
} package src;
import java.io.BufferedWriter; import java.io.IOException; import java.io.OutputStreamWriter; import java.net.ServerSocket; import java.net.Socket;
public class Server {
public static void main(String[] args) throws IOException { ServerSocket server = new ServerSocket(6666); Socket client = server.accept(); BufferedWriter bf = new BufferedWriter(new OutputStreamWriter(client.getOutputStream())); bf.write("welcome"); bf.close(); client.close(); server.close(); }
} 注意:127.0.0.1是本机的IP地址,6666是客户端口