iSocket.Read(iBuffer,status) can't reset iBuffer

Login to reply to this topic.
Tue, 2005-02-15 23:42
Joined: 2003-12-30
Forum posts: 93
Hi

I have a problem understanding the behaviour of iSocket.Read(iBuffer,status) and why iBuffer is always appending the new received data instead of show each message separately. Here is my code snippet (inspired from http://www.symbian.com/developer/techlib/papers/Sockets/sockets.html) for the RunL and the getBufferContent methods :
Code:
TBuf<256> iBuffer;

void MySocketEngine::RunL(void)
{
     //Means that the Accept was ok;
      if (iStatus==KErrNone)
     {
       
// I would like to clear the content of iBuffer, so that
// new data can be received.
// iBuffer.Delete(0,iBuffer.Length());
 TRequestStatus stat;
 iSocket.Read(iBuffer,stat);
     }

   
}


HBufC* MySocketEngine::GetBufferContent()
{
HBufC* myStr = HBufC::NewL(256)
myStr->Des().Copy(iBuffer);
return myStr

}
When calling GetBufferContent i receive (for n messages sent ) : Message1 Message2 and so on, as if everything was appended ( It would be kinda ok, but the fact that i'm explicitely doing a iBuffer.Delete ( I also tried with Zero() ) should erase the whole content of the iBuffer. Or have i missed something ?
Thanx a lot for your help !

MatD:-)

MatD


Wed, 2005-02-16 04:38
Joined: 2004-10-25
Forum posts: 69
iSocket.Read(iBuffer,status) can't reset iBuffer
hi Matd,

I user iBuffer.Zero() and it works fine for me.

The only difference is that I don;t use it directly
in the iSocket.Read() method. This is how I do it.

iBuffer.Zero();
IssueRead(iBuffer);
and then the IssueRead method is implemented as follows.

Code:
void CSocketsReader::IssueRead(TDes8& rcv_buffer)
   {
   // Initiate a new read from socket into iBuffer
   __ASSERT_ALWAYS(!IsActive(), User::Panic(KPanicSocketsEngineRead, ESocketsBadState));
 
   iSocket.Recv(rcv_buffer, 0, iStatus);
   SetActive();
   }

Let me know if this helps.
Thu, 2005-02-17 22:42
Joined: 2003-12-30
Forum posts: 93
iSocket.Read(iBuffer,status) can't reset iBuffer
Hi !

Thx a lot for your help. It works fine and i also put the iBuffer.Zero out of the code, because it was not necessary for me. I just wanted to mention something very very very curious.
I was testing this code snippet for receiving a message on socket, with a Java SocketClient. And I found out the following tricky problem:

On the SocketServer Side ( Symbian ) my Buffer msg has a size of five (TBuf<5> msg).

First I've used this Java code snippet to send a message:

Code:
PrintWriter out = new PrintWriter(socket.getOutputStream());
String text = "Hello World";
out.println(text);
out.println("\n\r");

The received message on my Symbian Server was :

1 -
2 -   Worl
3 -  d

First line (1) : nothing ( the message was always cut by the size of my Symbian side buffer ) why Huh?
Second line (2) : (blank space)World
Third line : d
My initial message always began with empty characters. Increasing the size of the buffer hasn't helped Sad

I've then changed my Java SockClient into :

Code:
BufferedOutputStream out;
out = new BufferedOutputStream(socket.getOutputStream());
String text = "Hello World"
out.write(text.getBytes());
out.flush();

And now it works Smiley

Can someone explain me, what went wrong ? Why had I to change my PrintWriter into a BufferedOutputstream ? I have the feeling that the Printwriter is sending more chars than needed and doesn't send it correctyl ( or isn't correctly received by the C++ side).

MatD

MatD

Fri, 2005-02-18 04:46
Joined: 2004-10-25
Forum posts: 69
iSocket.Read(iBuffer,status) can't reset iBuffer
yeah, flushing the stream definitely helps.

aprt from that I think its best NOT to use \r and \n
although they are written correctly at the java side,
they are not interpreted correctly at the symbian side.
I too had this problem earlier, and I had to remove
all the \r\n in the data that is being exchanged.

Best/Safest option is to convert everything in to a byte array
and send it out and flush the stream.

-sourabh
  • Login to reply to this topic.