首先处理异常的方法通常有两种 抛或者try 不过我的问题点并不在这上面
代码跟毕老师写的完全一样,但是出现以下问题
1.当将异常抛出时
异常抛出的时候throws Exception
Exception in thread "main" java.net.NoRouteToHostException: No route to host: co
nnect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:529)
at java.net.Socket.connect(Socket.java:478)
at java.net.Socket.<init>(Socket.java:375)
at java.net.Socket.<init>(Socket.java:189)
at PicClient.main(UploadPic.java:8)------>Socket s = new Socket("192.168.1.254",10007);
2.当将异常try时
try 的时候
java.net.NoRouteToHostException: No route to host: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:351)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:213)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:200)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:366)
at java.net.Socket.connect(Socket.java:529)
at java.net.Socket.connect(Socket.java:478)
at java.net.Socket.<init>(Socket.java:375)
at java.net.Socket.<init>(Socket.java:189)
at Client.main(Client.java:11) ---->Socket s = new Socket("192.168.1.254",10007);
通过以上两点 我个人理解是 问题都出现在Socket s = new Socket("192.168.1.254",10007);这句话上
通过之前的(PlainSocketImpl.java:351)
(PlainSocketImpl.java:213)
等似乎是说我写的不合法,但是我查看htem里面的方法(域名,端口)是没错的啊,那么问题到底出在什么地方
|
|