I am trying to write a simple networked chat program in Java. I have almost no networking experience. I was wondering what resources I should begin looking at (beside here of course).
Sticking with the core Java API would be best for now.
I am trying to write a simple networked chat program in Java. I have almost no networking experience. I was wondering what resources I should begin looking at (beside here of course).
Sticking with the core Java API would be best for now.
Google is your friend. Search for "java socket programming tutorial" or something like that and you'll get lots of results, including the one suggested by zxcv as well as these:
http://www.javaworld.com/javaworld/jw-12-1996/jw-12-sockets.html
http://www.cafeaulait.org/books/jnp/javanetexamples/index.html
Nio or the traditional way with ServerSocket or Socket See java.net package
Nio docs here.
Here's a pretty basic, easy to read Java networking tutorial too:
http://tutorials.jenkov.com/java-networking/index.html
I found a great tutorial into networking and java from sun's own website: http://download.oracle.com/javase/tutorial/networking/TOC.html
The socket section even has you write a mini client / server chat demo.
"Head First Java" is a great beginners book and they do a tutorial on creating a simple chat program.
http://oreilly.com/catalog/9780596004651/
It's much more straight-forward than you would think. Honestly I'd just start browsing through the javadocs for the nio package. They should even contain mini-tutorials and source code.
Beyond that, java.sun.com should be littered with tutorials.
If you don't understand sockets---well I could send you to a reference but it's easier to just tell you--sockets are a way 2 programs talk to each other. They are just a unique number that (when combined with your IP address) give you a unique path to a program. So if I "Listen" on port (socket) 1000, then another program connects to port 1000, anything the connecting program sends, the listening program receives.
Use a high port number (higher than, say, 5000) because there are many programs that assign their own port.
This is how virtually everything on your computer communicates.
You might want to read a really brief intro to socket communications if the API is still confusing.