Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Problem buffering data with DataOutputStream and DataInputStream

 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've written another topic but I made a mistake with the explanation and also with the title of the topic, so I'll try once more now!

I'm doing a client-server application. The Client send data contained into a Mensaje object (previously serialized with a DataOutputStream) using a DatagramSocket. The server recieves the datagram and dumps the byte array to a new Mensaje object using a DataInputStream (that's the goal of the getRequest() function); then it processes the information, and, finally, it sends the response to the client. The communication is not the problem, it works fine.

So, to simplify, I didn't add the communication module: I'm only giving to you a function called getRequest() that recieves as argument a Mensaje object, which should be modified. To simplify, I didn't add the communication module, so, into the getRequest() function I'm simulating that server recieves a byte array (called buffer) from line 20 to 30. Then, from 32 to 41, the server retrieves data from buffer, and represents it on screen. After that, coming back to main() function, the Mensaje object data is once more time printed on screen.

Now, I will paste a simplified code that represents my problem.


Sample.java



Mensaje.java


The results thrown running Sample are:

During getRequest():
tipoMensaje = 0
idInvocacion = 0
idMetodo = 0
longArgumentos = 13
argumentos = [B@7c6768

After getRequest():
tipoMensaje = 0
idInvocacion = 0
idMetodo = 0
longArgumentos = 13
argumentos = [B@7c6768


But I don't understand why is it hapenning, beacause at the getRequest() invocation, I've setted tipoMensaje = 1 and idInvocacion = 1, so I was expecting the next results:

During getRequest():
tipoMensaje = 1
idInvocacion = 1
idMetodo = 0
longArgumentos = 13
argumentos = [B@7c6768

After getRequest():
tipoMensaje = 1
idInvocacion = 1
idMetodo = 0
longArgumentos = 13
argumentos = [B@7c6768


I don't either understand why longArgumentos and argumentos are correcty setted and tipoMensaje and idInvocacion not.

Thanks in advance!
HernĂ¡n.
 
Marshal
Posts: 27211
87
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
They are set correctly (I think). However this line of code:

isn't really a good test of whether setTipoMensaje() was called correctly or not. Look at it closely.

And that isn't the only instance of the "Copy, Paste, Forget to Change" anti-pattern in your posted code. Look at all of it closely.
 
Hernan Blanco
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
OMG! I had checked and rechecked my code and I didn't find the error! (I was looking for any more complex...).

Setters of idInvocacion and idMetodo wasn't in the correct way.

Thanks a lot!!
 
You're not going crazy. You're going sane in a crazy word. Find comfort in this tiny ad:
ScroogeXHTML - fast RTF to HTML and XHTML conversion
https://coderanch.com/t/749563/ScroogeXHTML-fast-RTF-HTML-XHTML
reply
    Bookmark Topic Watch Topic
  • New Topic