Introduction

Today’s tutorial will focus on some of the basic tools and techniques you will need to successfully complete Assignment 1.

Sockets in Java

Implementing the DICT client requires communicating with a DICT server over the internet, specifically using TCP connections. Although we haven’t encountered TCP in class yet, Java provides a convenient abstraction (the Socket class) which allows us to create TCP connections without worrying about how the protocol works.

We’ll be working through the Oracle tutorial on Java Sockets found here: https://docs.oracle.com/javase/tutorial/networking/sockets/index.html.

Start by reading through the section What is a Socket?. Don’t hesitate to ask your peers or the TA for help if something seems unclear. Once you’ve read through this section, you can proceed onto the next section.

Reading from and Writing to a Socket demonstrates a small client and server program. You’re encouraged to download the programs and experiment with them in your local development environment. If time permits, you can take a look at a more complex socket program in Writing the Server Side of a Socket.

Netcat

It may be helpful to see what kind of output the DICT server produces before you start implementing your client. Netcat is a tool that was introduced in last week's tutorial. If you haven't completed that portion of Tutorial 0, you should go do that now.

Code Reading

For the first assignment you’re tasked with implementing a limited subset of the DICT client protocol. We’ve provided you with some starter code as well as a number of helper classes which will help you design and test your implementation.

When working with a new codebase it’s helpful to read through the code that already exists to ensure you don’t end up reimplementing functionality that already exists! Understanding pre-existing codebases is a very useful skill for any programming you will do in future jobs, projects, etc.

For this activity, read through the following classes and describe in 1-2 sentences what each class does or how it can be used in your A1 implementation:

Debugging

Wireshark

What is Wireshark?

Wireshark is a network analyzer. It is a handy tool that allows you to look at packets and see what is going on while debugging.

You can download it here.

Exercise: Let's Capture Conversation with dict.org!

Open up Wireshark, we see a welcome page:

Opening Wireshark

It shows a list of network interfaces. We can select the "any" interface.

NOTE: If you don't have the "any" interface, select anything that says "wifi..." or any interface that shows some pattern.

Capturing Interface

Now things pop up. These are the packets in the network traffic. There are too many of them. Since we are only interested in the ones we send to dict.org and the replies we get, we need some filtering.

Let's try tcp.port == 2628

Filtering Packets

After filtering, we see an empty list. This is because we have not send any packets to dict.org!

Recall from last tutorial, we can start a TCP connection to dict.org using netcat: netcat dict.org 2628

Netcat

Now, we see a bunch of packets. Right click on one of them, and click Follow -> Tcp Stream.

Follow

The entire conversation is dumped! If you look at the ones printed by netcat, these are exactly the same content.

TCP Stream Follow