第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

為什么我在客服端“new socket"時(shí)老是報(bào)錯(cuò)?

public?class?FileServer?{


????public?boolean?connectedClient()?throws?Exception{
????????ServerSocket?serverSocket?=?new?ServerSocket(8899);
????????Socket?socket?=?null;
????????int?count?=?0;
????????System.out.println("服務(wù)器已啟動(dòng),正在等待客戶(hù)端的連接。。。");
????????try?{
????????????while?(true)?{
????????????????socket?=?serverSocket.accept();
????????????????ServerThread?st?=?new?ServerThread(socket);
????????????????st.start();
????????????????count++;
????????????????InetAddress?ia?=?InetAddress.getLocalHost();
????????????????System.out.println("這是第"+count+"個(gè)客戶(hù)!");
????????????????System.out.println("連接主機(jī)的地址:"+ia.getHostAddress());
????????????}
????????}catch?(Exception?e){
????????????e.printStackTrace();
????????}
????????return?true;
????}

????public?static?void?main(String[]?args)?throws?Exception?{
????????FileServer?fs?=?new?FileServer();
????????fs.connectedClient();
????}
}
public?class?ServerThread?extends?Thread?{
????????private?Socket?socket;

????????public?ServerThread(Socket?socket){
????????????this.socket?=?socket;
????????}

????????public?void?run()?{

????????????????InputStream?is?=?null;
//????????????????OutputStream?os?=?null;
????????????????InputStreamReader?isr?=?null;
????????????????BufferedReader?br?=?null;
????????????????PrintWriter?pw?=?null;
????????????????String?s?=?null;
????????????????int?count?=?0;
????????????try?{
????????????????is?=?socket.getInputStream();
????????????????isr?=?new?InputStreamReader(is);
????????????????br?=?new?BufferedReader(isr);
????????????????while?((s=br.readLine())!=null){
????????????????????System.out.print(s);
????????????????}
????????????????socket.shutdownInput();
????????????????pw?=?new?PrintWriter(socket.getOutputStream());
????????????????pw.write("服務(wù)器歡迎您");
????????????????pw.flush();
????????????????socket.shutdownOutput();
????????????}?catch?(Exception?e)?{
????????????????e.printStackTrace();
????????????}finally?{
????????????????try?{
????????????????????if?(is!=null)
????????????????????????is.close();
????????????????????if?(isr!=null)
????????????????????????isr.close();
????????????????????if?(br!=null)
????????????????????????br.close();
????????????????????if(pw!=null)
????????????????????????pw.close();
????????????????}catch?(Exception?e){
????????????????????e.printStackTrace();
????????????????}
????????????}
????????}
}
public?class?FileClient?{

????public?static?void?main(String[]?args)?throws?Exception{
????????Socket?socket?=?null;
????????OutputStream?os?=?null;
????????PrintWriter?pw?=?null;
????????InputStream?is?=?null;
????????InputStreamReader?isr?=?null;
????????BufferedReader?br?=?null;
????????String?serverInfo?=?null;
????????socket?=?new?Socket("localhost",8800);
????????try?{
????????????os?=?socket.getOutputStream();
????????????pw?=?new?PrintWriter(os);
????????????pw.write("賬號(hào):admin??密碼:123");
????????????pw.flush();
????????????socket.shutdownOutput();
????????????is?=?socket.getInputStream();
????????????isr?=?new?InputStreamReader(is);
????????????br?=?new?BufferedReader(isr);
????????????while?((serverInfo=br.readLine())!=null){
????????????????System.out.println("服務(wù)器說(shuō):"+serverInfo);
????????????}
????????????socket.shutdownInput();
????????}catch?(Exception?e){
????????????e.printStackTrace();
????????}finally?{
????????????try?{
????????????????if?(is?!=?null)?{
????????????????????is.close();
????????????????}
????????????????if?(isr?!=?null)
????????????????????isr.close();
????????????????if?(br?!=?null)
????????????????????br.close();
????????????????if?(pw?!=?null)
????????????????????pw.close();
????????????????socket.close();
????????????}catch?(Exception?e){
????????????????e.printStackTrace();
????????????}
????????}
????}
}

Exception in thread "main" java.net.ConnectException: Connection refused: connect
?? ?at java.net.DualStackPlainSocketImpl.connect0(Native Method)
?? ?at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
?? ?at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:339)
?? ?at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:200)
?? ?at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:182)
?? ?at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
?? ?at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
?? ?at java.net.Socket.connect(Socket.java:579)
?? ?at java.net.Socket.connect(Socket.java:528)
?? ?at java.net.Socket.<init>(Socket.java:425)
?? ?at java.net.Socket.<init>(Socket.java:208)
?? ?at com.com.filetest.FileClient.main(FileClient.java:19)

正在回答

2 回答

你兩次的端口號(hào)不一樣,一個(gè)8800,另外一個(gè)是8899

0 回復(fù) 有任何疑惑可以回復(fù)我~
#1

moummm 提問(wèn)者

非常感謝!(好尷尬。。。)
2017-08-23 回復(fù) 有任何疑惑可以回復(fù)我~

FileClient的第18行應(yīng)為socket.getOutputStream(),獲取輸出流,為了發(fā)送數(shù)據(jù)

0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消

為什么我在客服端“new socket"時(shí)老是報(bào)錯(cuò)?

我要回答 關(guān)注問(wèn)題
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢(xún)優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)