码迷,mamicode.com
首页 > 编程语言 > 详细

Exception in thread "main" java.net.BindException: Address already in use: JVM_Bind

时间:2017-08-26 22:49:58      阅读:337      评论:0      收藏:0      [点我收藏+]

标签:output   als   输出流   sed   ann   ready   res   输出   dex   

技术分享
 1 import java.io.PrintStream;
 2 import java.net.Socket;
 3 import java.net.ServerSocket;
 4 import java.util.Scanner;
 5 
 6 public class Server
 7 {
 8     public static void main(String[] args)
 9         throws Exception
10     {
11         ServerSocket ss = new ServerSocket(30000);
12         Socket socket = ss.accept();
13         PrintStream ps = new PrintStream(socket.getOutputStream());
14         ps.println("服务器的第一行数据");
15         ps.println("服务器的第二行数据");
16         // 关闭socket的输出流,表明输出数据已经结束
17         socket.shutdownOutput();
18         // 下面语句将输出false,表明socket还未关闭。
19         System.out.println(socket.isClosed());
20         Scanner scan = new Scanner(socket.getInputStream());
21         while (scan.hasNextLine())
22         {
23             System.out.println(scan.nextLine());
24         }
25         scan.close();
26         socket.close();
27         ss.close();
28     }
29 }
View Code

运行上面代码,出现下面错误:

技术分享

ServerSocket ss = new ServerSocket(30000);//错误在这一行,表明30000端口被占用,原因是可能有程序在占用30000端口,你可以换个端口试一试!

Exception in thread "main" java.net.BindException: Address already in use: JVM_Bind

标签:output   als   输出流   sed   ann   ready   res   输出   dex   

原文地址:http://www.cnblogs.com/lanshanxiao/p/7436486.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!