gpt4 book ai didi

JAVA:java.net.BindException: 地址已被使用: JVM_Bind

转载 作者:可可西里 更新时间:2023-11-01 02:55:10 26 4
gpt4 key购买 nike

<分区>

我已经写了这两个类,一个用于客户端,另一个用于服务器。当我同时运行它们时,出现以下错误:

java.net.BindException: Address already in use: JVM_Bind...

问题是什么?我还使用 TCPview 软件,只有两个 java.exe 使用相同的端口。这两个 java.exe 进程属于应用程序。

代码如下:

服务器代码

/**
*
* @author casinoroyal
*/
public class server {
public static ServerSocket socket1;
public static void main(String[] args) {
try {
socket1 = new ServerSocket(1254);
String request="";
Socket mylink=socket1.accept();
System.out.println("server feels=====");
DataInputStream input= new DataInputStream(mylink.getInputStream());
DataOutputStream output=new DataOutputStream(mylink.getOutputStream());
Scanner chat=new Scanner(System.in);

while(!request.equals("QUIT")){
request=input.readUTF();
output.writeUTF(chat.next());
}

socket1.close();
} catch (IOException ex) {
System.out.println(ex);
}
}
}

客户端代码

package javaapplication9;
import java.net.*;
import java.io.*;
import java.util.*;
public class client {
//main
public static void main(String[] args) {
System.out.println("client want to be connected");
try {
Socket mysock = new Socket(InetAddress.getLocalHost(),1254);
System.out.println("client has been connected");
DataInputStream input = new DataInputStream(mysock.getInputStream());
DataOutputStream output = new DataOutputStream(mysock.getOutputStream());
String reque="";
Scanner scan1=new Scanner(System.in);
String sendmsg=scan1.next();

while(!reque.equals("QUIT")){
output.writeUTF (sendmsg);
reque=input.readUTF();
}

mysock.close();
} catch (IOException ex) {
System.out.println("client rejected"+ex);
}
}
}

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com