views:

545

answers:

5

Hi everyone,

I'm going to create a project in some month in a course I'm having and for that purpose I would like to read and try making some small test programs regarding the network / socket programming in Java.

Ideally, what I'm looking for is a tutorial with description and a end program to create where I can between two computers send and resive small and simple text messages. Don't have to be any GUI or something like that just the simple version.

I've read some articles from Sun's own homepage and in one of my Java Book but I seem to be missing the last piece of the puzzle to really understand that "network programming".

In addition, I don't know if I'm mixing things now but to my understanding can the multithreading paradigm also be applied to the network / socket programming.

Therefore, my question is, if anyone knows about a good tutorial or educational link for me to get an overview of this topic. I’m not totally new to Java but haven’t got any experience in this type of programming.

Thanks - Emil

+1  A: 

from my experience and on my opinion, when you want to learn programming at the level of abstraction provided by the Java Network API, you also have to be familiar with java IO and Threads. there are a lot of tutorials out there, i suggest you grab a book. just a thought!

ultrajohn
+1  A: 

For basic steps you might wan't to read this tutorial Sockets programming in Java. In this model the most people used one thread to handle one network connection.

In java 1.4 NIO was introduced, this makes intros a bit more complex: Java NIO Tutorial.

NIO allows to use a Selector which allows you to handle many connections in one thread, which leads to higher performance.

stacker
+2  A: 

There is no universal book for this kind of learning. The best bet is to start with java's own tutorial on sockets/threads etc here.

By encountering problems once you start the implementation it is then you will start learning, preferably by visiting SO again and asking a bunch of specific code questions.

Milan
+3  A: 

Here is a nice sample chapter from Java Network Programing. There's also some other parts available here, and also sample sources are available.

If you'd decide to buy this book, I'd say these chapters are enough for now:

  • Chapter 2. Basic Network Concepts
  • Chapter 3. Basic Web Concepts
  • Chapter 4. Java I/O
  • Chapter 5. Threads
  • Chapter 6. Looking Up Internet Addresses
  • Chapter 7. URIs and URLs
  • Chapter 9. Sockets for Clients
  • Chapter 10. Sockets for Servers

Don't bother about NIO yet; it's quite advanced.

In addition, I don't know if I'm mixing things now but to my understanding can the multithreading paradigm also be applied to the network / socket programming.

Yes, indeed it's a very important aspect. You'll find out why once you've read the sample chapter.

Have fun!

Enno Shioji
I actually own that book. It explains the different terms a lot in easy to understand language. But there is also the problem, instead of explaining the needed stuff, it goes on and has too much unnecessary information. Each time I needed something, after reading in the book, I ended on java's tutorial page or somewhere else where the information was much better and more "to the point".
Milan
+1  A: 

I've only read the C version of this book, but likely Java version is going to be equally short and good: Calvert and Donahoo's TCP/IP Sockets in Java: Practical Guide for Programmers. Even if you learned socket programming in C, you could probably adapt to Java's implementation fairly quickly.

alt text

eed3si9n