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.
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.
Nio or the traditional way with ServerSocket or Socket See java.net package
Nio docs here.
Sun's Java API and official tutorials are probably the best place to get your feet wet.
Thought of this one too, but you were faster finding it :-)
Edit: Man... Stackoverflow is so damn fast... My post was thought as a response to the first entry and after posted there are two more. Awesome!
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
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.
I recommend you to first learn networking. If you have time read the Tanenbaum book, the greatest reference in networking. If you want a quick leard, here is a road map:
Then go with Java: Socket, ServerSocket, DatagramSocket, RMI, etc.
"Head First Java" is a great beginners book and they do a tutorial on creating a simple chat program.
http://oreilly.com/catalog/9780596004651/
Here's a pretty basic, easy to read Java networking tutorial too: