Java-Gaming.org
Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
Featured games (78)
games approved by the League of Dukes
Games in Showcase (407)
games submitted by our members
Games in WIP (293)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  UDP Two Sockets, One port, Local  (Read 1695 times)
0 Members and 1 Guest are viewing this topic.
Offline counterp

Senior Member


Medals: 11



« Posted 2011-09-28 01:57:31 »

Is it possible for a packet to be sent to a specific socket that is listening on the same port as another socket in a different application, in UDP.

At the moment, it only picks one of the sockets to always send the packets to (the first socket listening). the second socket doesn't receive anything.

Visualization:

I have a SERVER, and two sockets, SOCKET1 and SOCKET2.

SOCKET1 listening on 127.0.0.1:1837
SOCKET2 listening on 127.0.0.1:1837

SERVER sending packet to 127.0.0.1:1837

SOCKET1 will always receive the packets, can i specify for SOCKET2 to receive certain packets, and SOCKET1 certain others?
Offline ra4king

JGO Kernel


Medals: 264
Projects: 2


I'm the King!


« Reply #1 - Posted 2011-09-28 04:49:50 »

Nope.

Offline theagentd
« Reply #2 - Posted 2011-09-28 12:31:18 »

Just sort them yourself? If YOU can't do that, how do you expect the OS to do it for you? xd

Myomyomyo.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline counterp

Senior Member


Medals: 11



« Reply #3 - Posted 2011-09-28 15:59:47 »

like I said, only first socket receives the packets.

darn ittt there must be a work around?
Offline SimonH
« Reply #4 - Posted 2011-09-28 16:49:56 »

I've been trying to work out why you need to do this...?
Why not just use another port for socket2 or filter the packets from socket1?

Heroes' Keep is in development.
Meanwhile try Bloodridge
Offline sproingie
« Reply #5 - Posted 2011-09-28 17:35:47 »

You should have gotten an exception when you attempted to bind two sockets to the same port.  The only way you can bind two sockets to the same port is with multicast, and I suspect that's not actually what you're after.

Offline counterp

Senior Member


Medals: 11



« Reply #6 - Posted 2011-09-29 04:24:47 »

it is multicast (as intended), problem is both sockets don't receive the packets, only one does.

EDIT: fixeddddd
Offline sproingie
« Reply #7 - Posted 2011-09-29 06:12:18 »

127.0.0.1 is not a multicast address, and you are not using a multicast API.  Just saying it's multicast does not make it multicast.  I'd link to the proper API for multicast sockets, but I really don't want to confuse the issue further than I already have.

Offline counterp

Senior Member


Medals: 11



« Reply #8 - Posted 2011-09-29 07:51:54 »

I'm aware... doesn't change the fact that the sockets are listening on 127.0.0.1

Offline ra4king

JGO Kernel


Medals: 264
Projects: 2


I'm the King!


« Reply #9 - Posted 2011-09-29 13:24:51 »

counterp, how did you fix it?

Games published by our own members! Check 'em out!
Play the free demo of Revenge of the Titans!
Offline counterp

Senior Member


Medals: 11



« Reply #10 - Posted 2011-09-30 05:14:18 »

I was trying to send a UDP packet to a SocketAddress instead of a group (I was using multicast sockets), but when I do this, it only sends it to the first socket registered (instead of all sockets listening on that specific address and port). I could send a UDP packet to the whole group, and everyone, including the two sockets listening on the same address and port would receive it.

I didn't want that though because the information sent had to do with sending a unique ID to a specific client that I wanted to remain private.

I just used TCP in the end since it's a one time thing (sends ID on login), and I also needed reliability for this. (should have done this from beginning)
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

Play Revenge of the Titans! The situation is critical. We need fancy commanders to defend Earth, the moon, Mars!
 
Browse for soundtracks for your game!

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

The invasion has landed! On Mars! And you're there to beat 'em!
cubemaster21 (90 views)
2013-05-17 21:29:12

alaslipknot (99 views)
2013-05-16 21:24:48

gouessej (129 views)
2013-05-16 00:53:38

gouessej (124 views)
2013-05-16 00:17:58

theagentd (135 views)
2013-05-15 15:01:13

theagentd (122 views)
2013-05-15 15:00:54

StreetDoggy (164 views)
2013-05-14 15:56:26

kutucuk (186 views)
2013-05-12 17:10:36

kutucuk (188 views)
2013-05-12 15:36:09

UnluckyDevil (195 views)
2013-05-12 05:09:57
Complex number cookbook
by Roquen
2013-04-24 12:47:31

2D Dynamic Lighting
by Oskuro
2013-04-17 16:46:12

2D Dynamic Lighting
by Oskuro
2013-04-17 16:45:57

2D Dynamic Lighting
by Oskuro
2013-04-17 16:23:20

Noise (bandpassed white)
by Roquen
2013-04-05 17:36:01

Noise (bandpassed white)
by Roquen
2013-04-03 16:17:38

Java Data structures
by Roquen
2013-03-29 13:21:12

Topic Request
by kutucuk
2013-03-22 21:42:01
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!
Page created in 0.095 seconds with 21 queries.