Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Passing vector to The Datagram Packet

 
AbhiKool Jain
Greenhorn
Posts: 7
Android Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to pass the whole v3 vector to the client, but do not want to affect the sending of existing data. Can you tell me how to do it??


>
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15214
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch.

Can you explain in more detail what exactly you mean by that you don't want to affect the sending of existing data?

Please note that class Vector is a legacy collection class from Java 1.1 (long ago!) - it's better to use ArrayList instead of Vector.
 
AbhiKool Jain
Greenhorn
Posts: 7
Android Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The program is a chat server, it receives a message from one client and sends the message to everyone connected to this server. The vector v3 contains the user name selected by the client. I just want to send the info of connected users to the server with the message. Is there any way I can send both the vector v3 and the user name to everyone, while not mixing them both? Or do I have to mix them somehow?
I'll try to use ArrayList for the program, but first let the logic complete, thanks for the suggestion
 
Ralph Cook
Ranch Hand
Posts: 479
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You are using a datagram socket; as far as I know, it just takes a stream of bytes and tries to deliver them to the specified address. It is up to the program receiving this data to do something intelligent with it; if you were to call toString on your Vector and pass that string into the socket, it will take it and transmit it, but the program getting that data must know how to tell the difference between it and anything else that comes.

If you send messages from party A to party B, for instance, perhaps that's just a(nother) String. The receiving program is not told that messages were written into the socket separately from Vectors, or from other messages, etc. It is up to the receiving program to know how to tell where one set of data ends and the next one starts. So you can create delimiters, counts of characters being sent, labels and tags, etc., it's all up to you. But the socket on the receiving end doesn't keep track of all that, to the socket it's just a stream of bytes.

Incidentally, a program can LOOK like these things are being delimited while being tested, because you don't have several of the messages being sent at one time. But it will fail when you do.

rc
 
AbhiKool Jain
Greenhorn
Posts: 7
Android Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Ralph, I understood the problem now and used some delimiters and A StringTokenizer to solve my problem now. Thanks for the help
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic