Java-Gaming.org Hi !
Featured games (90)
games approved by the League of Dukes
Games in Showcase (744)
Games in Android Showcase (225)
games submitted by our members
Games in WIP (825)
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  
  Multiple channels on same port  (Read 3380 times)
0 Members and 1 Guest are viewing this topic.
Offline darcone

Junior Devvie




Size matters


« Posted 2003-08-11 21:12:51 »

Why wont java.nio let me open several channels on the same port?
Offline kevglass

« JGO Spiffy Duke »


Medals: 319
Projects: 25
Exp: 22 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #1 - Posted 2003-08-12 03:56:37 »

Nice open question Smiley

If you mean open a completely new channel, its because the channel is associated with a socket. In UDP and TCP you can only have one socket bound to any port (note UDP and TCP are independant of each other tho).

Kev

Offline darcone

Junior Devvie




Size matters


« Reply #2 - Posted 2003-08-12 10:05:00 »

Hmm, then how can I accept multiple connections on the same port? Must I use the "main" port as control channel and tell the clients where to connect next? Doesnt make much sense, dont see why many channels shouldnt be able to bind the same port Smiley The connections can still be identified.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline kevglass

« JGO Spiffy Duke »


Medals: 319
Projects: 25
Exp: 22 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #3 - Posted 2003-08-12 10:17:29 »

Channels exist within sockets, however, you can only really have 2 channels per socket (1 in, 1 out). Sockets can not be bound to the same port.

You accept connections on the same port in TCP, but it then allocated a new socket/channel locally (under the hood) which you use to communicate with the client.

With UDP you can send and recieve to/from which ever address you like using the same port, just as long as you don't call connect(). However, this can be quite slow (using one channel for all comms).

Channels can't bind to anything, sockets bind. Sockets can't bind to the same port. How would the Operating System know who to deliver packets to? e.g. 2 applications came up, both bind to port 3000 using TCP. A packet arrives at the machine for port 3000 using TCP, which application do you deliver it to? both? neither? choose a random one?

Equally, you couldn't identify the source of a packet fully without having a fully qualified (port included) at the other end of the socket.

Kev

Offline darcone

Junior Devvie




Size matters


« Reply #4 - Posted 2003-08-12 10:49:20 »

Then how would I do it "under the hood" ? For example, consider a telnet server... It lets clients connect and then what? As far as I know the telnet client can´t be told to connect to another port on the server, and it would also complicate it all with firewall etc...
Offline kevglass

« JGO Spiffy Duke »


Medals: 319
Projects: 25
Exp: 22 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #5 - Posted 2003-08-12 12:01:11 »

The socket created locally doesn't have a port, its actually just a file descriptor that allows packets to be recieved and sent.

When you do...

ServerSocket s = new ServerSocket(1000);
Socket newConnection = s.accept();

The newConnection socket is wrapped round the file descriptor that is passed back from the listening socket. However, its a completely seperate channel and file descriptor. It doesn't have to send anything back to the other end since at the TCP layer recieved packet is sent to the right FD.

Outgoing connections always need their own port.

Kev

Kev

Offline darcone

Junior Devvie




Size matters


« Reply #6 - Posted 2003-08-12 12:39:41 »

Ahh, wow, I didnt know that Smiley So I can basically have one ServerSocketChannel running and create new SocketChannels from that one with accept() , and after that I dont have to create any new ServerSocketChannels to get new connections?

Btw thanks for taking time and helping me out Smiley
Offline kevglass

« JGO Spiffy Duke »


Medals: 319
Projects: 25
Exp: 22 years


Coder, Trainee Pixel Artist, Game Reviewer


« Reply #7 - Posted 2003-08-12 12:47:00 »

Yep, one server socket, lots of connected people..

Not a problem btw, its what makes the community really cool..

Kev

Offline Misk

Innocent Bystander




Yeah!


« Reply #8 - Posted 2004-12-19 17:19:23 »

Smiley Thanks for discussing this, it was very helpful.
Pages: [1]
  ignore  |  Print  
 
 

 
Ecumene (149 views)
2017-09-30 02:57:34

theagentd (214 views)
2017-09-26 18:23:31

cybrmynd (300 views)
2017-08-02 12:28:51

cybrmynd (288 views)
2017-08-02 12:19:43

cybrmynd (296 views)
2017-08-02 12:18:09

Sralse (291 views)
2017-07-25 17:13:48

Archive (968 views)
2017-04-27 17:45:51

buddyBro (1094 views)
2017-04-05 03:38:00

CopyableCougar4 (1667 views)
2017-03-24 15:39:42

theagentd (1428 views)
2017-03-24 15:32:08
Java Gaming Resources
by philfrei
2017-12-05 19:38:37

Java Gaming Resources
by philfrei
2017-12-05 19:37:39

Java Gaming Resources
by philfrei
2017-12-05 19:36:10

Java Gaming Resources
by philfrei
2017-12-05 19:33:10

List of Learning Resources
by elect
2017-03-13 14:05:44

List of Learning Resources
by elect
2017-03-13 14:04:45

SF/X Libraries
by philfrei
2017-03-02 08:45:19

SF/X Libraries
by philfrei
2017-03-02 08:44:05
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!