• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Socket Problems

 
Frank hogan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got following code to send a text message to a smalltalk server connected over TCP/Socket. Its a simple request-response action, Java engine send message ( text , actually a method and parameters) and Smalltalk engine receives and converts text into a method with parameters and excutes and sends back the XML response.

The problems I am having is I recieve Junk response sometimes thats not related, or sometimes I get incorrect response, or a delayed response after
some time.
Any thoughts?
Thanks


private synchronized Element send(User user, String message) throws Exception {

System.out.println(
new java.util.Date(System.currentTimeMillis()).toString()
+ " Engine sending "
+ user.getUserId() + " " + message);
if(DESTINATION == null) throw new Exception("EEngine has not been properly configured ");
DESTINATION.receive(r)
..}
[ May 09, 2006: Message edited by: Frank hogan ]
 
Edwin Dalorzo
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well you seem to be using DatagramSockets and that implies many things that you have to take into account.

First, you must know that the maximum amount of data transmitted in a DatagramPacket is 65,507 bytes.

Hence, you must be sure the XML file you are expecting to receive is smaller than that.

If not (which might be be your problem) you will have to send it in chunks of data. As DatagramSocket uses UDP (not TCP) protocol, you cannot ensure that the subsequent packages are going to arrive in order, worst even, if you are using multithreading programming to read the packages, one of you threads may perfectly be reading packages of another's thread request.

What I mean is that DatagramSocket can receive data from different senders connected to the same host and port. It is not like TCP sockets, which by means of Streams the comunication channel is controlled between client and server.

Finally, UDP sockets are not secure, which means that your data may perfectly never get to the other side and your DatagramSocket will never even get acquainted of that.

Maybe you should use TCP sockets instead.

At least that's what I think it is happening. What do you guys think?

[ May 09, 2006: Message edited by: Edwin Dalorzo ]
[ May 10, 2006: Message edited by: Edwin Dalorzo ]
 
Frank hogan
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Edwin,
Thanks for response. But I am using TCP sockets and I/O streams and BufferedReaders to read data.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic