Is Android blocking UDP packets from outsite? - java

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?

Related

Android multicastsocket send is dropping packets

I have an app which continuously sends data in multicast socket after joining to a specific IP group. After sending packets for few hours, all of a sudden it stops sending data. From java socket send is successfull but there is no packet info in tcpdump as well as network packet capture. I have debugged till datagramsocketimpl class, there doesn't seems to have any problem. Suspecting the problem some where after that. Has anyone seen this issue? The data packet just doesn't reach wifi driver. The issue happens randomly no specific procedure.

How to get an acknowledgement for the client socket from server?

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.

Communication between two clients of web application

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.

Java SE Socket Input Stream does not get response

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.

client server interaction question

I am trying to implement a minimal chat server in java over regular TCP protocol. The chat server will listen on a specific port. The question I have is if there are multiple clients sending messages to the same port, can the server distinguish between the clients and respond to each individually if the messages do not contain the IP address or destination name of the client?
to make my question a bit more clear, suppose the server gets a packet that contains only
"user: abc to-user:efg message:"Hello""
Can I find out in java the address of the client who sent the packet and respond back to the same address or will I need to include some identifier in the message itself like "sender-ip = 1.1.1.1"
Multiple clients will never send data over the same port. The only time your clients will talk over the same port is when they will connect to the server. In the server, whenever the ServerSocket receives a connection it returns a new Socket. This socket is a combination of the following : Server IP+ServerPort and Client IP+Client Port. The Server IP and the Server Port will be same for each socket; what differs is the client IP and Port. Usually this socket is passed to a new thread for further communication while the ServerSocket goes back to listen to incoming connections. Once you have a reference to the socket you can call socket..getInetAddress().getHostAddress() to get the remote IP and socket.getPort() to get the port of the respective client.
Yes, each connection will be separate - you'll have a different stream to read from for each connection. It's up to you to associate the relevant user information with the connection though.

Categories