Two Sockets for Only One Connection [closed] - java

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I am making an instant messenger in Java and I want to add the ability to send images as well as text. The first thing that came to mind was to make new Sockets and input and output streams. Firstly, will this work and is it good practice. Secondly, if this doesn't work then how does the receiving end of the message figure out if what it is receiving is an image or a String?

An output stream contains bytes, which you have to build into messages. The reader knows which type of data you sent, because the sender will have to say which type of message it is sending.
e.g. if you write say "image" as a string you could assume that what follows it is an image.

Remember that you're not transmitting Strings or Images, you're exchanging Messages. A message should have a content or message type associated with it.

Related

when should I remove/register the 'read operation' in java nio selector? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 6 months ago.
Improve this question
in my understanding,'read operation' is always being registered.At some places, i find the fact that 'read operation' could be removed
When you don't want to be notified when there's data ready to read.
For various setups you always want to process any bytes available to read as soon as possible, in which case, you register that you're interested in the read event and never remove it.
However, there are various protocols where you want to stop being notified. Primarily, when you cannot actually process the bytes; if you keep that registered, you'll keep being 'woken up' continually, which is not what you want.
For example:
You are sending the read data on to something else, and that 'something else' is currently not ready to receive more, for example, its buffers are full (if it's also a NIO based thing, it not ready for writing right now). In this case you can't keep 'reading', as you have no place to put what you read.
You are currently writing some data out and the protocol you've set up isn't designed to be interruptible like this - you want to finish sending the message before receiving a new message in return. However, you haven't written it all out yet (for example, because there's plenty to send, you haven't sent it all yet, and the channel is not currently ready for writing).

Change tag 31 in Fix4.4 [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I am using FIX protocol and I need tag 31 to be of string type.
Originally it is of type price which means a float or double.
I was just wondering if it will have issues(currently i don't see any issues)
Thanks in advance.
Assuming you are using QuickFIX/J, you only tagged fix-protocol and java.
Since the data is transmitted over the wire as Strings anyway you won't have issues with your counterparty.
The only issue that might occur is that when receiving messages you need to make sure that your data dictionary and your code both process the field correctly. You cannot be sure that the received value in the field will be of type "price" anymore. Your counterparty could now send any String value in the field which could make your code fail.
But in general every value is converted to String internally anyway.

Ways to pass an ArrayList with socket [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
What is the best way to pass an ArrayList<Object> from server to client?
After i have to put my ArrayList in a JTable.
You have to serialize it when you write to the socket and deserialize when you read from the socket.
Ultimately you're sending Strings on the wire. Transport doesn't know or care anything about objects on either end of the conversation. TCP/IP is language independent.
You have many choices to choose from:
Java Serializable - this means sending byte code on the wire.
XML. You can use JAXB.
JSON. You can use Jackson.
Custom protocol of your own design.

Java - What is the fastest way for reading a file [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
I want to read a file as a string. Every line of this file contains information that I use to construct new objects.
I wonder what is the fastest way of doing that. Obviously, there are two options. The first is to read the whole file and create the objects by reading the string. The second is to read the data line by line and create a new object after every readLine(). Is there a real performance deference or I can go either way?
If there is an object every couple of lines and it won't affect anything else after or before it I would go for the line by line approach. However, if there is parsing involved with nested objects or a more complicated file structure read it all first

Why my send and receive Object sometime is different? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I trying to send an object by server to receiver or reverse.However, most of time it is true and done completely but sometimes when I send an object, the receiver get the object that I sent before it and object are sent by sender lost.I have used Socket in my project and read and write by ObjectInputStream and ObjectOutputStream.
If you're sending the same object with different values you need to call ObjectOutputStream.reset() before the second send if you want the receiver to get the changed object. Or call writeUnshared() instead of writeObject().

Categories

Resources