hiya all,how can i transfer an array of strings from a client machine to a server machine ?how do i convert to from arrays of string to 1's and 0's on the client side and vice versa?

Dani AI

Generated

Short practical answer: send the String[] as an encoded message over a socket instead of trying to hand-convert characters into literal “1”s and “0”s. As and pointed out, sockets and serialization are the right building blocks; the points below fill in the choices, concrete patterns, and pitfalls they did not show.

If both ends are Java, the fastest way to prototype is Java serialization (ObjectOutputStream / ObjectInputStream). It is easy but brittle (class versioning) and can be a security risk if you deserialize untrusted input. If you need language-agnostic or safer transport, use JSON (Gson/Jackson) or a compact schema format (Protocol Buffers, MessagePack). If you send raw bytes, always frame the message (prefix with length) so the receiver knows message boundaries.

Example patterns (minimal):

/* client: send a String[] via Java serialization */
try (Socket s = new Socket(host, port);
     ObjectOutputStream oos = new ObjectOutputStream(s.getOutputStream())) {
    oos.writeObject(myStringArray);
    oos.flush();
}
/* server: read the String[] */
try (ServerSocket ss = new ServerSocket(port);
     Socket s = ss.accept();
     ObjectInputStream ois = new ObjectInputStream(s.getInputStream())) {
    String[] received = (String[]) ois.readObject();
}

Alternative JSON + framing:

String json = new Gson().toJson(myStringArray);
byte[] b = json.getBytes("UTF-8");
dos.writeInt(b.length); dos.write(b); dos.flush();

Troubleshooting and cautions: when using Object streams bidirectionally, construct and flush ObjectOutputStream before creating ObjectInputStream on the same connection to avoid blocking. Always handle IOException and ClassNotFoundException, declare serialVersionUID for serializable classes, and avoid deserializing untrusted data (use whitelisting or a safer format). For production, use TLS (SSLSocket), test locally first, and prefer JSON or Protobuf for cross-language robustness and security.

Recommended Answers

All 2 Replies

client machine to a server machine

Ever heard of Sockets, and also you do not need to send 1's and 0's you can send entire objects by using serialization (Some resource on serialization -- 1,,,4).
Here is a link to The Java Tutorial on Networking.

I may not be able to answer this question eventually but could guide the first few steps. Well, you don't need to convert the array strings to 1s and 0s and then the 1s and 0s to analog signals that flow in wires all you have to do is throw the data from the client machine by opening a connection with the server on whatever socket the server listens and then on the server side receive the dataand it will be as it was sent bu you. On the server side you could listen to incoming conenctions from various clients by using the method of the ServerSocket class.

You could also "flatten" the array to a file and then send this file over to the server where it inflates it to proper type (assumes type is known). Here the flattening is called serialization and the inflation of the object from the file is called deserialization.

You could always google the terms with "java" to find more about them.

Edit : Damn !!! stephen84s kept it short just to beat me to it. ;)

commented: He may have kept it short but he had more links ;) +9
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.