Ep. 16: Server Packet Receiving – Network Chat Programming

Github commit for this episode:


In this video:
– How to start a server
– How to listen for data
– How to receive data as a server
– How to create a server


Steam Group:


Outro music is by Approaching Nirvana:


46 thoughts on “Ep. 16: Server Packet Receiving – Network Chat Programming”

  1. Btw, can anyone help me? xD I get an exception when i try to connect :/
    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException

  2. Hey Cherno, I am considering going into app dev. for the android. I have experience in c, c++, java, and python. I was wondering if you would consider doing a tutorial on app dev. in the near future. I think your audience would be interested in it.

  3. Hey cherno I know you don't like this but I have idea for Game Programming. The idea is that we draw map inside of game rather than drawing it in 3rd party sofware.

    I hope you can make it 😀

  4. I still think UDP is actually unreliable because it may crash your network if the server just forces it self to shutdown and the UDP packets have nowhere to go and just flood your network

  5. You should show us how to export the files into runnable and regular jar files. I watched your 3D tutorials where you export to an runnable jar file. But it doesn't really work with the server etc.

  6. Come on guys, there are 600 views, we can give him more like, I mean you do like, right? it helps him, inspires him to do more, and gives us more content to watch 🙂

  7. I've checked line by line now, and yet when i enter a message in the client, it doesn't show up for the server, I would very much appreciate if someone were to explain what I've done wrong.

  8. I don't think that's the case, because in Eclipse the program runs fine without errors or anything, but when I export it this error occurs.

  9. You may not have Java set up properly. Try running cmd and type java and see what happens, if it is working you should get a list of options.

  10. Java is set up properly. I do get a list of options and I usually play Minecraft and code other things in Java, so yes it is set up properly. This is not the case :/

  11. For some reason, depending on the size of the byte array, the console prints out a ton of spaces after it receives a message. If i change the byte size form 1024 to something like 512 the spaces reduces by half. So it's connected to the byte[] length… but i don't know why it's only doing it to me.

  12. Figured it out. instead of String string = new String(packet.getData()); I had to change it to String string = new String(packet.getData(), 0, packet.getLength(), "UTF-8"); Because for some reason, i need the packets to be 8 bit to send correctly. I believe this fixes Calos Martinez' Problem.

  13. I'm having a problem where in the console after I type a message it shows the message and then it shows a bunch of question marks in boxes. Please help 🙁

  14. I have done it like you said but the only thing i get to see in my console is Usage: java -jar ChernoChatServer.jar [port]

    how do i fix this?

  15. I didnt get the error!!!  Im assuming that means Im not opening the socket and in fact when I send I dont recieve nothing in the sever side!!   But doesnt look wrong :/ and the server is not recieveng anything :/

  16. I still don't understand why do you need a separate thread for sending messages from the client? The socket.send() method executes instantly, unlike socket.receive(). And you don't even need a thread for that either, since the GUI already runs on its own separate thread and the application won't freeze. Using threads in the client app would only make sense when connecting to multiple servers.

  17. In receiveClients method in Server what exactly happens when you call socket.recieve(packet);?
    I heard him say the server socket will then wait for a packet but what I'm trying to understand is
    does the while loop start waiting the first or the second time around that it crosses the socket.recieve(packet); step and why??.

    I'm a noob and I have a bit of trouble with this recursive stuff (if this is recursion). Plz help

  18. hey bro! From this tutorial I was trying to do something like u but problem is my manage thread and receive thread doesn't running. What should I do for this problem? Please give me solution.

Leave a Reply