You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by Ashish <pa...@gmail.com> on 2010/02/02 10:47:23 UTC
Re: Please help me. A question about Apache Mina no---signature
On Tue, Feb 2, 2010 at 2:50 PM, Steve Ulrich <st...@proemion.com> wrote:
> Hi!
>
>> Ashish [mailto:paliwalashish@gmail.com] wrote:
>>
>> On Tue, Feb 2, 2010 at 12:41 PM, Meysam Ebrahimi <se...@gmail.com>
>> wrote:
>> > Hi,
>> >
>> > My name is Meism.
>> > I have a project that should work with socket. I have to write server
>> side
>> > code via Apache Mina and client side bye pure java NIO.
>> > I couldn't send message to mina server as usual, but when I remove
>> this line
>> > from Mina server class :
>> > *chain.addLast("codec", new ProtocolCodecFilter(new
>> > TextLineCodecFactory()));*
>>
>> U can't work without a Codec or a filter. You need to know how to
>> convert messages to bytes and vice-versa..
>
> Of course you can, if you do the the en-/decoding before passing the WriteRequest.
I didn't knew that :-( too bad for me...
>> > Mina server can receive message from client, but when I want to use
>> > *session.write("message
>> > received") *to send a message from server to client , I get an
>> exception
>> > like this:
>> > *Don't know how to handle message of type 'java.lang.String'. Are
>> you
>> > missing a protocol encoder?*
>> >
>> > What is the problem?
>
> Your name suggests, that your platform default encoding isn't US-ASCII.
> So you have to make sure, you are using a propper encoding on *both* sides (i would recommend a UTF encoding).
>
> Additionally the Text*Line*CodecFactory can only forward a message as complete, if it receives a line delimiter (Either "\n" or "\r\n" in most cases)
>
> Just try to send "text\n" instead of "text" and the TextLine decoder will know that the line ended.
>
>> Add the codec and things will work fine..
>
> He just said that it won't ;-)
oops ! :-(