Java: Best Place to Begin Learning Basic Networkin

2019-02-04 20:36发布

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.

8条回答
一纸荒年 Trace。
2楼-- · 2019-02-04 20:47

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

查看更多
疯言疯语
3楼-- · 2019-02-04 20:55

Nio or the traditional way with ServerSocket or Socket See java.net package

Nio docs here.

查看更多
虎瘦雄心在
4楼-- · 2019-02-04 20:57

Here's a pretty basic, easy to read Java networking tutorial too:

http://tutorials.jenkov.com/java-networking/index.html

查看更多
甜甜的少女心
5楼-- · 2019-02-04 20:59

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.

查看更多
放我归山
6楼-- · 2019-02-04 21:00

"Head First Java" is a great beginners book and they do a tutorial on creating a simple chat program.

http://oreilly.com/catalog/9780596004651/

查看更多
迷人小祖宗
7楼-- · 2019-02-04 21:04

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.

查看更多
登录 后发表回答