DatagramSocket problem

I have a client sending out a request to the server on a DatagramSocket on port 9876 (to the servers ip). The server is listening on a DatagramSocket on port 9876 so that i can get the request. Once it gets the request, the server will send out a responce to a group of addresses (all the clients).

The problem is, the Client is listening on a MulticastSocket on port 9876 for the responce from the server, but it hears its own request that it sent out on that same port, and so it thinks its gotton a reply from the server (even though it hasnt). This happens even if the sever isnt running so thats how i know it must be hearing its own request and thinking its a server responce. The client and server are on the same computer so they will have the same ip address. Maybe this is why the client is getting his own request back, cause technically it is addressed to him?

Anyone know how i can fix this problem?
Thanks.

Look at the source port? Or put something in the packet that identifies whether it came from a client or a server.

Kev

but even if i put something in saying “client” that wont stop it from recieving the packet int he 1st place.

what u mean byt look at the source port? the client is sending/recieving on the same port and the server.

Yes, but if it recieves a message but knows it came from a client it can ignore it?

Kev

i could get it and ignore it like u said, but once the client has recieved the packet, the server doesnt get it. Is there any way of identifying the server so i can send a packet to it not just by ip?

Why is the client using a multicast and the server using a unicast?

Kev

The client is sending out on a DatagramSocket cause its only going to 1 address, the server. The Server gets it on a DatagramSocket and sends back out on a DatagramSocket, but its sending out to all clients (an InetAddress group), not just to one client. So the client has to listen on a multicastSocket that has been added to this group to be able to receive the msg from the server.
So, any way of giving a name to a server so that when i send a packet to it, it can send it to its name, not just to its ip? Cause theres a client on the same computer so is getting his own requests, not the server!

Keep one port for multicast and another for direct comms?

Kev

so u mean make the client send out on the DatagramSocket on port 1, then the Server receive on a DatagramSocket on port 1, then the Server send out on a DatagramSocket on port 2, and the client receive on a MulticastSocket on port 2?

can u have a look at my new Thread in this networking section please? title is “java.io.StreamCorruptedException”
thanks