File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Passing vector to The Datagram Packet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Passing vector to The Datagram Packet" Watch "Passing vector to The Datagram Packet" New topic

Passing vector to The Datagram Packet

AbhiKool Jain

Joined: Apr 03, 2011
Posts: 7

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??


The Pirate[/b]
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15093

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.

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
AbhiKool Jain

Joined: Apr 03, 2011
Posts: 7

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

Joined: May 29, 2005
Posts: 479
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.

AbhiKool Jain

Joined: Apr 03, 2011
Posts: 7

Thanks Ralph, I understood the problem now and used some delimiters and A StringTokenizer to solve my problem now. Thanks for the help
I agree. Here's the link:
subject: Passing vector to The Datagram Packet
It's not a secret anymore!