Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (489)
Games in Android Showcase (112)
games submitted by our members
Games in WIP (555)
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 Server help!  (Read 1909 times)
0 Members and 1 Guest are viewing this topic.
Offline darcone

Junior Member




Size matters


« Posted 2003-11-17 11:00:19 »

I am trying to implement UDP using NIO in some way... I tried it the same way I am with TCP;

1  
2  
3  
4  
5  
6  
case UDPServer:
               
                channel = DatagramChannel.open();
                ((DatagramChannel)channel).socket().bind(new InetSocketAddress("localhost", port));
                clients = new Vector();
                break;


and then to register:

1  
channel.register(selector, SelectionKey.OP_ACCEPT);


I get an exception at that last line:

1  
2  
3  
4  
5  
java.lang.IllegalArgumentException
        at java.nio.channels.spi.AbstractSelectableChannel.register(AbstractSelectableChannel.java:170)
        at java.nio.channels.SelectableChannel.register(SelectableChannel.java:254)
        at SpeedConn.SpeedChannel.register(SpeedChannel.java:209)
        at SpeedConn.SpeedConn.run(SpeedConn.java:43)


Anyone got a hint?
Offline blahblahblahh

JGO Coder


Medals: 1


http://t-machine.org


« Reply #1 - Posted 2003-11-17 12:36:08 »

I'm getting a sense of deja vu here; AFAICS this was covered in other people's replies to your earlier post on the same topic? Perhaps more appropriate if you continue that topic with whatever you're not understanding:

http://www.java-gaming.org/cgi-bin/JGNetForums/YaBB.cgi?board=Networking;action=display;num=1060213621;start=0#0

In particular:

"With udp there is no client and server as with tcp. You don't connect with the other machine. The connect() function in Datagram channel do not create a real connection with an other machine. It just locks the address that you can send to. Because the client don't connect to the server, the server don't accept either. It just reads the packets it recieves and checks the address to know where it come from. You have to keep track of which address represents which sender."

So, there is no meaning to listening for connects to UDP (which is what OP_ACCEPT is for).

However, I confess to having been responsible for a hijack of that thread, where it ended up discussing TCP performance in extreme situations.

malloc will be first against the wall when the revolution comes...
Offline darcone

Junior Member




Size matters


« Reply #2 - Posted 2003-11-17 22:42:20 »

Ok I managed to "start" a UDP "server" with java.NIO and it can read datagrams and see where they are coming from. Now I tried to send datagrams back to the origin, but my client couldnt see anything coming back. Is it me being to tired a monday night or am I doing it the wrong way? I know the client code works because Ive been querying game server with it for some time now.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline blahblahblahh

JGO Coder


Medals: 1


http://t-machine.org


« Reply #3 - Posted 2003-11-18 08:13:38 »

Quote
Ok I managed to "start" a UDP "server" with java.NIO and it can read datagrams and see where they are coming from. Now I tried to send datagrams back to the origin, but my client couldnt see anything coming back. Is it me being to tired a monday night or am I doing it the wrong way? I know the client code works because Ive been querying game server with it for some time now.


Just to check the obvious - you need to ALSO run your server code on the client, and your client code on the server, if you want to send data from the server to the client.

As has been said before, UDP is connectionless. I.e. there is no connection. I.e. if someone sends you stuff, you cannot "reply" you can only send them stuff from scratch, as if you'd never heard from them.

But maybe that's not your problem?

malloc will be first against the wall when the revolution comes...
Offline darcone

Junior Member




Size matters


« Reply #4 - Posted 2003-11-18 12:53:57 »

I think my problem was that I wasnt sending replies to my clients via the server socket but rather creating new client sockets on the server for each client. This would mean the messages to the client would not come from the same port as the server socket but from a new one and the security check would just disregard those messages.
Offline darcone

Junior Member




Size matters


« Reply #5 - Posted 2003-11-18 15:23:00 »

Yeah that was it. Now I have a pretty nice abstraction of both TCP and UDP Smiley
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

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

The first screenshot will be displayed as a thumbnail.

Nickropheliac (12 views)
2014-08-31 22:59:12

TehJavaDev (23 views)
2014-08-28 18:26:30

CopyableCougar4 (27 views)
2014-08-22 19:31:30

atombrot (40 views)
2014-08-19 09:29:53

Tekkerue (38 views)
2014-08-16 06:45:27

Tekkerue (34 views)
2014-08-16 06:22:17

Tekkerue (24 views)
2014-08-16 06:20:21

Tekkerue (34 views)
2014-08-16 06:12:11

Rayexar (72 views)
2014-08-11 02:49:23

BurntPizza (47 views)
2014-08-09 21:09:32
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
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!