Socket Programming with Java NIO - Channels, Selectors, and Buffers

preview_player
Показать описание
In this video we'll cover SOCKET PROGRAMMING using the JAVA NIO library. We'll make an example client/server aplication where the server only requires one thread to handle multiple client connections! In the process we'll touch on CHANNELS, SELECTORS, and BUFFERS, and why byte order and ENDIANNESS matter in computer networking.Network byte order is BIG ENDIAN, but you should always confirm byte order when implementing a networking protocol.

I'm Will Tollefson, a guy who loves to NEVER STOP LEARNING and teach others what I've learned. If you're enjoying the content, please LIKE, SUBSCRIBE, and SHARE!

Code on GitHub:

VIDEO CHAPTERS:
0:00 Why Java NIO Sockets?
1:34 Channels and Selectors in the Server
3:33 Configuring the Selector
8:40 Client Connections
14:32 Implementing the Client
17:37 ByteBuffer Tips and Tricks
28:22 Making an Echo Server
31:18 Endianness, Big vs Little Endian
Рекомендации по теме
Комментарии
Автор

After 5 years of working on Java, Still think I am missing a lot..! Thanks B/W..!

sumanthanumula
Автор

Fantastic socket programming tutorial, Will! You give fantastic examples and explain everything very clearly. 😀

DenaTollefson
Автор

I just love these Java socketing videos. You're the best!

NatiShen
Автор

Great job explaining this. Very informative and fun.

moncefabboud
Автор

you're awesome man, you should have way more suscribers and views

senorgriffin
Автор

Subscribed!! I've been trying to make a program that has multiple chatrooms (and also multiple clients) but i'm stumped (bordering on desperate). I just can't figure out how to get more than one chatroom working. Do you possibly have any tips for me?

submersedsoap
Автор

Hi Will, I'm just learning NIO channels now. If I'm performing File I/O on Android (using kotlin now), should I stick to channels or should I just use the kotlin io approach of file.appendBytes(byteArray)? Might you have knowledge on that?

mattm
Автор

Very nice, I use the same code, jdk 11, debug on Eclipse 4.24.0, process stops at selector.select(); Any suggestion?

Daxin-mc
Автор

Can I broadcast the message to other clients ?

tried in else part not working
else {
buffer.flip();
var message = new String(buffer.array(), buffer.position(), byteRead);
System.out.println(message);
while (buffer.hasRemaining()) {
for (var otherClient : clients) {
if(otherClient != client) otherClient.write(buffer);
}
}
buffer.clear();
}

tahidurrahman
Автор

can someone from another network join the chat with this method

alxbudn
join shbcf.ru