Hi Trustin,

Thank you for the quick reply.

The Object was actually quite small, I've also tried with a "new
Integer(123)" but the same exception would still happen.

Is there any workarounds that can re-organize UDP packets received with
MINA? I've done a search in the forum, and found there isn't many posts
about broadcasting. Do you have any examples about sending datagram using
MINA at hand that I can have a look?

Very much appreciated,
Qi




Trustin Lee wrote:
> 
> I think your message doesn't fit into one UDP packet, which mean your
> message is truncated.  It can always happen in UDP if you are sending
> a relatively big object.
> 
> HTH,
> Trustin
> 
> On Dec 13, 2007 4:37 PM, Qi <[EMAIL PROTECTED]> wrote:
>>
>> Hi there,
>>
>> I was writing some prototype codes that uses MINA to broadcast some
>> message
>> in a heterogeneous network.
>> For simplicity and fast development time, I used
>> ObjectSerializationEncoder/Decoder.
>> Somehow, a exception was occurred when sending messages(serializable
>> object)
>> between a windows machine and a linux machine. (detailed exception stack
>> trace is attached at the end of this post.)
>> Messages sent from windows to windows boxes are fine.
>> Plain strings between windows and Linux also been received normally.
>> I just wonder if anyone has met this problem before?
>>
>> Thanks in advance,
>> Qi
>> 13 Dec. 2007
>>
>> The windows machine has windows XP SP2 (32bit), JRE 1.6.0 installed.
>> The Linux machine has fedora 5 (Linux version 2.6.20-1.2320.fc5) and JRE
>> 1.6.0.
>>
>> Here's the full stack trace:
>> ExpiringMapExpirer-1 [INFO ] [/192.168.1.100:3207] CLOSE -
>> mina.BroadcastReceiver$1
>> ExpiringMapExpirer-1 [INFO ] [/192.168.1.100:3207] CLOSED -
>> mina.BroadcastReceiver$1
>> session closed
>> DatagramAcceptor-0 [INFO ] [/192.168.1.21:33435] CREATED -
>> mina.BroadcastReceiver$1
>> session created
>> DatagramAcceptor-0 [INFO ] [/192.168.1.21:33435] OPENED -
>> mina.BroadcastReceiver$1
>> DatagramAcceptor-0 [INFO ] [/192.168.1.21:33435] RECEIVED:
>> HeapBuffer[pos=0
>> lim=106 cap=128: 00 00 00 66 AC ED 00 05 73 72 00 27 62 6F 6F 2E 63 6F 6D
>> 6D
>> 6F 6E 73 2E 63 61 63 68 65 2E 65 76 65 6E 74 2E 4D 6F 63 6B 59 6F 6F 62
>> 65
>> 72 45 76 65 6E 74 78 72 00 2B 62 6F 6F 2E 63 6F 6D 6D 6F 6E 73 2E 63 61
>> 63
>> 68 65 2E 65 76 65 6E 74 2E 41 62 73 74 72 61 63 74 59 6F 6F 62 65 72 45
>> 76
>> 65 6E 74 78 70 74 00 03 31 32 33] - mina.BroadcastReceiver$1
>> DatagramAcceptor-0 [WARN ] [/192.168.1.21:33435] EXCEPTION: -
>> mina.BroadcastReceiver$1
>> org.apache.mina.filter.codec.ProtocolDecoderException:
>> org.apache.mina.common.BufferDataException: java.io.EOFException
>> (Hexdump:
>> empty)
>>         at
>> org.apache.mina.filter.codec.ProtocolCodecFilter.messageReceived(ProtocolCodecFilter.java:164)
>>         at
>> org.apache.mina.common.support.AbstractIoFilterChain.callNextMessageReceived(AbstractIoFilterChain.java:299)
>>         at
>> org.apache.mina.common.support.AbstractIoFilterChain.access$1100(AbstractIoFilterChain.java:53)
>>         at
>> org.apache.mina.common.support.AbstractIoFilterChain$EntryImpl$1.messageReceived(AbstractIoFilterChain.java:648)
>>         at
>> org.apache.mina.filter.LoggingFilter.messageReceived(LoggingFilter.java:89)
>>         at
>> org.apache.mina.common.support.AbstractIoFilterChain.callNextMessageReceived(AbstractIoFilterChain.java:299)
>>         at
>> org.apache.mina.common.support.AbstractIoFilterChain.access$1100(AbstractIoFilterChain.java:53)
>>         at
>> org.apache.mina.common.support.AbstractIoFilterChain$EntryImpl$1.messageReceived(AbstractIoFilterChain.java:648)
>>         at
>> org.apache.mina.common.support.AbstractIoFilterChain$HeadFilter.messageReceived(AbstractIoFilterChain.java:499)
>>         at
>> org.apache.mina.common.support.AbstractIoFilterChain.callNextMessageReceived(AbstractIoFilterChain.java:299)
>>         at
>> org.apache.mina.common.support.AbstractIoFilterChain.fireMessageReceived(AbstractIoFilterChain.java:293)
>>         at
>> org.apache.mina.transport.socket.nio.support.DatagramAcceptorDelegate.readSession(DatagramAcceptorDelegate.java:400)
>>         at
>> org.apache.mina.transport.socket.nio.support.DatagramAcceptorDelegate.processReadySessions(DatagramAcceptorDelegate.java:368)
>>         at
>> org.apache.mina.transport.socket.nio.support.DatagramAcceptorDelegate.access$1200(DatagramAcceptorDelegate.java:61)
>>         at
>> org.apache.mina.transport.socket.nio.support.DatagramAcceptorDelegate$Worker.run(DatagramAcceptorDelegate.java:320)
>>         at
>> org.apache.mina.util.NamePreservingRunnable.run(NamePreservingRunnable.java:51)
>>         at java.lang.Thread.run(Unknown Source)
>> Caused by: org.apache.mina.common.BufferDataException:
>> java.io.EOFException
>>         at
>> org.apache.mina.common.ByteBuffer.getObject(ByteBuffer.java:1530)
>>         at
>> org.apache.mina.filter.codec.serialization.ObjectSerializationDecoder.doDecode(ObjectSerializationDecoder.java:92)
>>         at
>> org.apache.mina.filter.codec.CumulativeProtocolDecoder.decode(CumulativeProtocolDecoder.java:133)
>>         at
>> org.apache.mina.filter.codec.ProtocolCodecFilter.messageReceived(ProtocolCodecFilter.java:157)
>>         ... 16 more
>> Caused by: java.io.EOFException
>>         at java.io.ObjectInputStream$PeekInputStream.readFully(Unknown
>> Source)
>>         at
>> java.io.ObjectInputStream$BlockDataInputStream.readUTFBody(Unknown
>> Source)
>>         at java.io.ObjectInputStream$BlockDataInputStream.readUTF(Unknown
>> Source)
>>         at java.io.ObjectInputStream.readUTF(Unknown Source)
>>         at java.io.ObjectStreamClass.readNonProxy(Unknown Source)
>>         at java.io.ObjectInputStream.readClassDescriptor(Unknown Source)
>>         at
>> org.apache.mina.common.ByteBuffer$3.readClassDescriptor(ByteBuffer.java:1516)
>>         at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source)
>>         at java.io.ObjectInputStream.readClassDesc(Unknown Source)
>>         at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
>>         at java.io.ObjectInputStream.readObject0(Unknown Source)
>>         at java.io.ObjectInputStream.readObject(Unknown Source)
>>         at
>> org.apache.mina.common.ByteBuffer.getObject(ByteBuffer.java:1528)
>>         ... 19 more
>> Exception caught
>> ExpiringMapExpirer-1 [INFO ] [/192.168.1.21:33435] CLOSE -
>> mina.BroadcastReceiver$1
>> ExpiringMapExpirer-1 [INFO ] [/192.168.1.21:33435] CLOSED -
>> mina.BroadcastReceiver$1
>> session closed
>>
>> /****************************************
>> The acceptor code:
>> BroadcastReceiver.java
>> *******************************************/
>> package mina;
>>
>> import java.io.IOException;
>> import java.net.InetSocketAddress;
>>
>> import org.apache.mina.common.ByteBuffer;
>> import org.apache.mina.common.IoHandlerAdapter;
>> import org.apache.mina.common.IoSession;
>> import org.apache.mina.common.PooledByteBufferAllocator;
>> import org.apache.mina.common.SimpleByteBufferAllocator;
>> import org.apache.mina.common.ThreadModel;
>> import org.apache.mina.filter.LoggingFilter;
>> import org.apache.mina.filter.codec.ProtocolCodecFilter;
>> import
>> org.apache.mina.filter.codec.serialization.ObjectSerializationCodecFactory;
>> import org.apache.mina.transport.socket.nio.DatagramAcceptor;
>> import org.apache.mina.transport.socket.nio.DatagramAcceptorConfig;
>>
>>
>> public class BroadcastReceiver {
>>         public static void main(String[] args) throws IOException {
>>                 ByteBuffer.setUseDirectBuffers(false);
>>                 ByteBuffer.setAllocator(new SimpleByteBufferAllocator());
>>                 DatagramAcceptor receiver = new DatagramAcceptor();
>>                 DatagramAcceptorConfig config = new
>> DatagramAcceptorConfig();
>>                 config.setThreadModel(ThreadModel.MANUAL);
>>                 config.getSessionConfig().setBroadcast(true);
>>                 config.getSessionConfig().setReuseAddress(true);
>>                 config.getFilterChain().addLast("log", new
>> LoggingFilter());
>>                 ObjectSerializationCodecFactory oscf = new
>> ObjectSerializationCodecFactory();
>>                 oscf.setDecoderMaxObjectSize(1048576);
>>                 config.getFilterChain().addLast("codec",
>>                                 new ProtocolCodecFilter(oscf));
>>                 receiver.bind(new InetSocketAddress(7500), new
>> IoHandlerAdapter() {
>>
>>                         @Override
>>                         public void exceptionCaught(IoSession session,
>> Throwable cause)
>>                                         throws Exception {
>>                                 System.out.println("Exception caught");
>>                                 cause.printStackTrace();
>>                         }
>>
>>                         @Override
>>                         public void messageReceived(IoSession session,
>> Object message)
>>                                         throws Exception {
>>                                 System.out.println("message received:" +
>> message.toString());
>>                         }
>>
>>                         @Override
>>                         public void sessionClosed(IoSession session)
>> throws Exception {
>>                                 System.out.println("session closed");
>>                         }
>>
>>                         @Override
>>                         public void sessionCreated(IoSession session)
>> throws Exception {
>>                                 System.out.println("session created");
>>                         }
>>                 }, config);
>>         }
>> }
>>
>>
>> /*******************************************
>> *The connector side code:
>> BroadcastSender.java
>> *******************************************/
>> package mina;
>>
>> import java.net.InetSocketAddress;
>>
>> import org.apache.mina.common.ByteBuffer;
>> import org.apache.mina.common.ConnectFuture;
>> import org.apache.mina.common.IoHandlerAdapter;
>> import org.apache.mina.common.IoSession;
>> import org.apache.mina.common.PooledByteBufferAllocator;
>> import org.apache.mina.common.ThreadModel;
>> import org.apache.mina.common.WriteFuture;
>> import org.apache.mina.filter.LoggingFilter;
>> import org.apache.mina.filter.codec.ProtocolCodecFilter;
>> import
>> org.apache.mina.filter.codec.serialization.ObjectSerializationCodecFactory;
>> import org.apache.mina.transport.socket.nio.DatagramConnector;
>> import org.apache.mina.transport.socket.nio.DatagramConnectorConfig;
>>
>> public class BroadcastSender {
>>   public static void main(String[] args) {
>>     ByteBuffer.setUseDirectBuffers(false);
>>     ByteBuffer.setAllocator(new PooledByteBufferAllocator());
>>     DatagramConnector sender = new DatagramConnector();
>>     DatagramConnectorConfig config = new DatagramConnectorConfig();
>>     config.getFilterChain().addFirst("log", new LoggingFilter());
>>     config.getFilterChain().addFirst("codec",
>>         new ProtocolCodecFilter(new ObjectSerializationCodecFactory()));
>>     config.getSessionConfig().setBroadcast(true);
>>     config.setConnectTimeout(2);
>>
>>     config.setThreadModel(ThreadModel.MANUAL);
>>     config.getSessionConfig().setReuseAddress(true);
>>     ConnectFuture cf = sender.connect(new
>> InetSocketAddress("192.168.1.255",
>> 7500),
>>         new IoHandlerAdapter() {
>>
>>           @Override
>>           public void exceptionCaught(IoSession session, Throwable cause)
>> throws Exception {
>>             cause.printStackTrace();
>>             System.out.println("exceptionCaught");
>>           }
>>
>>           @Override
>>           public void messageSent(IoSession session, Object message)
>> throws
>> Exception {
>>             System.out.println("messageSent");
>>           }
>>
>>           @Override
>>           public void sessionClosed(IoSession session) throws Exception {
>>             System.out.println("sessionClosed");
>>           }
>>
>>           @Override
>>           public void sessionCreated(IoSession session) throws Exception
>> {
>>             System.out.println("sessionCreated");
>>           }
>>
>>           @Override
>>           public void sessionOpened(IoSession session) throws Exception {
>>             System.out.println("sessionOpened");
>>           }
>>
>>         }, config);
>>     cf.join();
>>     if (cf.isConnected()) {
>>       IoSession session = cf.getSession();
>>       WriteFuture wf = session.write(new MockEvent("123"));
>>       wf.join();
>>       session.close();
>>       session.getCloseFuture().join();
>>     }
>>   }
>> }
>>
>> /*************************
>> MockEvent.java
>> ************************/
>> package mina;
>>
>> public class MockEvent implements  Serializable  {
>>   private static final long serialVersionUID = -147055975212279720L;
>>
>>   private String message;
>>
>>   public MockEvent (String message) {
>>     this.message = message;
>>   }
>>   public String toString() {
>>     return message;
>>   }
>> }
>>
>>
>>
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Problem-when-use-ObjectSerializationCodecFactory-in-Datagram-broadcasting-between-linux-and-window-tp14311279s16868p14311279.html
>> Sent from the Apache MINA Support Forum mailing list archive at
>> Nabble.com.
>>
>>
> 
> 
> 
> -- 
> what we call human nature is actually human habit
> --
> http://gleamynode.net/
> --
> PGP Key ID: 0x0255ECA6
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Problem-when-use-ObjectSerializationCodecFactory-in-Datagram-broadcasting-between-linux-and-window-tp14311279s16868p14311480.html
Sent from the Apache MINA Support Forum mailing list archive at Nabble.com.

Reply via email to