I have a client socket which sends messages to the server.I want to get an acknowledgement on the client side whenever the server receives the message. Is it possible to get that acknowledgement. I developed the client using apache mina. Thanks in advance.
There are no messages in TCP, only a byte stream. There is an internal ACK mechanism that tracks how much of the stream has been correctly received, but it is not available to applications. If you want an acknowledgment from the server, your server will have to send it.
Related
I have a TCP/IP socket server which send multiple response to client based on client's requirement ( like send update whenever DB has an update). client sends xml and server too respond xml.
I stumbled on Netty yesterday. I want to know whether Netty can support my multiple response server application?
Sure as long as the protocol which is used can handle this kind of message flow.
I am using socket.io-java-client for connecting my java class on the server side to node.js and emit some events.
since I am running this on the server I dont want the socket thread to be running always.
As soon as my emit is done I want to disconnect the socket.
I tried
SocketIO socket=new SocketIO("http://IP:9001");
socket.emit("EVENT", "data");
socket.disconnect();
but this fails because we are closing the socket even before it has sent the message.
Is there any handler for emit success? How can I close the socket after the emit is successful?
After you've sent message to server, server can drop connection from its side. Just on event of receiving specific message it simply can disconnect that client socket.
Or server can additionally send response and client can close him self on receiving this response. But server should secure him self creating timeout in order to close idle clients who did not closed them self.
I recommend to do this operation on server side, and do not ever trust client side with such decisions.
Client can do it additionally after some timeout.
If you use Socket.IO just to send one message and close it after message sent, then there is no point to use Socket.IO as it will have overhead based on handshaking process, and you might consider using just HTTP request in order to send single messages to server.
I have just created a simple application, that sends a message to the server, and server replies back. Everything is good in local network, but when I am trying to do the same outsite my network, it is working in following way:
Client sends packet
Server receives packet
Server sends packet
Client doesn't receives packet.
To send anwser packet I am using InetAddress delivered with DatagramPacket.
What can cause this problem?
Let's say I want to send a message from one client to another. How should I approach this problem? Obviously I will have to send this message to server, but what's next? I have few ideas, but every idea seems to be wrong.
thanks
Client1 - send message for client2 to server
Client2 - check any period of time for the messages
OR
Client2 - Open Websocket to the server.
Client1 - send message for client2 to server
Server - push message to client2
direct client-to-client communication my be very difficult due to client firewalls.
Look at the tutorial for sockets in java
http://docs.oracle.com/javase/tutorial/networking/sockets/
Also you don't necessarily need a server. You can have the clients have both an incoming and outgoing channel and do it that way.
So
Client1 sends on its outgoing to Client2's incoming
Client2 hears on its incoming and responds on its outgoing to Client1's incoming
Client1 hears on its incoming
You can use the standard Java JMS approach to send asynchronous messages between applications. Read more at : http://java.sun.com/developer/technicalArticles/Ecommerce/jms/
If by web application you mean HTTP based, than you must know HTTP is a request based protocol. In other words, the server only responds to HTTP requests that come from the clients (browsers, most of the time), so after a client sends a message, all the other clients that want to receive that message must ask for it, i.e. make a request to the server. Typically, this is achieved using an auto-refreshed HTML page.
I have created a ServerSocket binded with a port in my application. I distribute this application to the connected PCs on the same network. I can post a request to any of the PC where the application is installed, using this port. Now the recepients can receive the messages, but when they send the response back to the requesting PC, the Input stream never receives the message. Is there a way to do it. I do not know any thing about URGENT TCP messages. I enabled it but I do not know how to send them. Is my message being discarded by default? I do not get the answer in other threads.
Do you flush the outputstream on the PCs sending data?
// Send data here
yourOutputStreamReference.flush();
There should be a loop in both ClientSocket and ServerSocket that keeps communication in the active state.
Otherwise: There should be implementation of both client socket and a server socket on all the sides (all the sender and receiver devices). When a server socket A receives a message, in order to reply back, there should be a client socket that replies back to server socket B which resides in the sender's application in his device.
In this way, all the devices with a server socket with the same port can detect and send messages to each other.
Of course the IP address of the sender should be kept in order to reply back.