Discussion:
[問題] socket的傳檔問題
(时间太久无法回复)
月亮們叫我改暱稱
2006-11-08 00:48:27 UTC
Permalink
我在Server端和Client端分別都宣告了

ObjectOutputStream 和 ObjectInputStream 兩個物件

用以互相傳送和接收訊息

~~~~~~~~~~~~~~~~~~~~~~~~~~

可是我的問題在於 input.readObject()會出問題

主因是我要接收的Object是我自行宣告的物件

雖然我在兩邊(Server端和Client端)都有宣告這個一模一樣的Object

不過我猜他還是不以為這是一樣的東西 orz


所以每次都會在此丟出IOException = =|||

而且我使用迴圈接收竟然會一直不停的丟....不是理論上會等有接到才動作嗎?

Ex: (xxx就是我自己定義的object物件)

while(socket.isconnect()){

try{
xxx temp=(xxx) input.readObject();---------
|
progress..................}//end try |
|
catch(IOException){ |
|
顯示錯誤點}//end catch <-----------

}//end while


這樣竟然會跑無窮回圈.......orz

代表xxx temp=(xxx) input.readObject();這行一直不停的運轉...

然後就造成程式死當了~~~囧


我猜是xxx沒有兩邊互通的關係吧@@?

請問要怎樣讓它接收一個我自己定義的物件呢?


另外,可以的話也順便解答一下:為什麼它會變無窮迴圈?
理論上是有接收到東西才動作的(我東西也只丟一次而已)


謝謝<(__ __)>

--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.112.241.154
月亮們叫我改暱稱
2006-11-08 02:14:57 UTC
Permalink
: 錯誤訊息?
他沒有錯誤訊息,他會丟出的IOException

我有接住,所以他是跑無窮迴圈........

程式非常難關掉 = =.......因為整個畫面都被這個迴圈拖累了

CPU 100%

--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.112.241.154
愚人
2006-11-08 03:06:47 UTC
Permalink
※ 引述《pluss (月亮們叫我改暱稱)》之銘言:
: : 錯誤訊息?
: 他沒有錯誤訊息,他會丟出的IOException
: 我有接住,所以他是跑無窮迴圈........
: 程式非常難關掉 = =.......因為整個畫面都被這個迴圈拖累了
: CPU 100%

while是pluss寫的

因此不是"他"

好歹也加一下Thread.sleep

才不會100%啊

你不加Thread.sleep

"他"就只好給你"一秒鐘十幾萬上下"了

--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 163.26.34.20
月亮們叫我改暱稱
2006-11-08 03:19:47 UTC
Permalink
我把printStackTrace的結果貼上來,麻煩板友了
-----------------------------------------------------------------------------
java.io.EOFException
at
java.io.ObjectInputStream$BlockDataInputStream.peekByte(ObjectInputStream.java:2502)
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1267)
at java.io.ObjectInputStream.readObject(ObjectInputStream.java:339)
at msn.fromserver.run(fromserver.java:66)
at msn.EnterMSN.jButton4_actionPerformed(EnterMSN.java:198)
at msn.EnterMSN_jButton4_actionAdapter.actionPerformed(EnterMSN.java:409)
at javax.swing.AbstractButton.fireActionPerformed(AbstractButton.java:1849)
at
javax.swing.AbstractButton$Handler.actionPerformed(AbstractButton.java:2169)
at
javax.swing.DefaultButtonModel.fireActionPerformed(DefaultButtonModel.java:420)
at javax.swing.DefaultButtonModel.setPressed(DefaultButtonModel.java:258)
at
javax.swing.plaf.basic.BasicButtonListener.mouseReleased(BasicButtonListener.java:234)
at java.awt.Component.processMouseEvent(Component.java:5488)
at javax.swing.JComponent.processMouseEvent(JComponent.java:3093)
at java.awt.Component.processEvent(Component.java:5253)
at java.awt.Container.processEvent(Container.java:1966)
at java.awt.Component.dispatchEventImpl(Component.java:3955)
at java.awt.Container.dispatchEventImpl(Container.java:2024)
at java.awt.Component.dispatchEvent(Component.java:3803)
at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4212)
at java.awt.LightweightDispatcher.processMouseEvent(Container.java:3892)
at java.awt.LightweightDispatcher.dispatchEvent(Container.java:3822)
at java.awt.Container.dispatchEventImpl(Container.java:2010)
at java.awt.Window.dispatchEventImpl(Window.java:1774)
at java.awt.Component.dispatchEvent(Component.java:3803)
at java.awt.EventQueue.dispatchEvent(EventQueue.java:463)
at
java.awt.EventDispatchThread.pumpOneEventForHierarchy(EventDispatchThread.java:242)
at
java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:163)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:157)
at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:149)
at java.awt.EventDispatchThread.run(EventDispatchThread.java:110)

--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.112.241.154
林思芃
2006-11-08 05:02:10 UTC
Permalink
p版友要不要把server及slient兩端

與建connection及取得input/output stream有關的code給貼上來阿?

目前就這些資料還真的看不出來為什麼會有問題呢^^"

--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 220.139.217.134
骨頭
2006-11-08 05:53:30 UTC
Permalink
※ 引述《pluss (月亮們叫我改暱稱)》之銘言:
: 我把printStackTrace的結果貼上來,麻煩板友了
: -----------------------------------------------------------------------------
: java.io.EOFException
at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1267)


http://java.sun.com/j2se/1.5.0/docs/api/java/io/EOFException.html
http://0rz.tw/b822m
http://www.javaworld.com.tw/jute/post/print?bid=29&id=105618


http://rafb.net/paste/results/ychOZ950.html

--
 String temp="relax"; | Life just like programing
 while(buringlife) String.forgot(temp); | to be right or wrong
 while(sleeping) brain.setMemoryOut(); | need not to say
 stack.push(life.running); | the complier will
 stack.push(scouting.buck()); | answer your life
 stack.push(bowling.pratice()); | Bone everything

--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 220.134.27.68

继续阅读narkive:
Loading...