Chapter 33 - Networking Flashcards

1
Q

What is an IP address?

A

An Internet Protocol (IP) address uniquely identifies the computer on the computer’s address. An IP address consists of four dotted decimal numbers between 0 and 255, such as 130.254.204.33. Since it is not easy to remember so many numbers, they are often mapped to meaningful names called domain names, such as liang.armstrong.edu.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is a DNS?

A

Special servers called Domain Name Servers (DNS) on the Internet translate host names into IP addresses. When a computer contacts liang.armstrong.edu, it first asks the DNS to translate this domain name into a numeric IP address and then sends the request using the IP address.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the “Internet Protocol”?

A

The Internet Protocol is a low-level protocol for delivering data from one computer to another across the Internet in packets.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is TCP?

A

The Transmission Control Protocol (TCP) is a higher-level protocol used in conjunction with the Internet Protocol.
TCP enables two hosts to establish a connection and exchange streams of data. TCP guarantees delivery of data and also guarantees that packets will be delivered in the same order in which they were sent.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is UDP?

A

The User Datagram Protocol (UDP) is a higher-level protocol used in conjunction with the Internet Protocol. UDP is a standard, low-overhead, connectionless, host-to-host protocol that is used over the IP. UDP allows an application program on one computer to send a datagram to an application program on another computer.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What protocol is used for stream-based communications, and what protocol is used for packet-based communication?

A

Stream-based communications used TCP for data transmission, whereas packet-based communications use UDP.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is the difference between TCP and UDP?

A

TCP is stream-based, UDP is packet-based. Since TCP can detect lost transmissions and resubmit them, transmissions are lossless and reliable. UDP, in contrast, cannot guarantee lossless transmission.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is a socket?

A

Sockets are the endpoints of logical connections between two hosts and can be used to send and receive data. Java treats socket communications much as it treats I/O operations; thus, programs can read from or write to sockets as easily as they can read from or write to files.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is the relationship between clients and servers?

A

Network programming usually involves a server and one or more clients. The client sends requests to the server, and the server responds. The client begins by attempting to establish a connection to the server. The server can accept or deny the connection. Once a connection is established, the client and the server communicate through sockets.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is a server socket, and what is a port?

A

To establish a server, you need to create a server socket and attach it to a port, which is where the server listens for connections. The port identifies the TCP service on the socket. Port numbers range from 0 to 65536, but port numbers 0 to 1024 are reserved fro privileged services.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Describe how a server and client connects, in three steps.

A
Step 1: Create a server socket on a port, e.g., 8000, using the following statement:
ServerSocket serverSocket = new ServerSocket(8000);

Step 2: Create a socket to connect to a client, using the following statement:
Socket socket = serverSocket.accept();

Step 3: A client program uses the following statement to connect to the server:
Socket socket = new Socket(serverHost, 8000);
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How to you create a server socket?

A

ServerSocket serverSocket = new ServerSocket(port);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What will happen if you try to create a server socket on a port already in use?

A

Attempting to create a server socket on a port already in use would cause the java.net.BindException.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

After a server socket is created, the server can use the following statement to listen for connections ____

A

Socket socket = serverSocket.accept();

This statement waits until a client connects to the server socket.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What statement does the client issue to request a connection to a server?

A

Socket socket = new Socket(serverName, port);

This statement opens a socket so that the client program can communicate with the server. ‘serverName’ is the server’s Internet host name or IP address.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

How do you create a socket to connect to the host 130.254.204.33 at port 8000?

A
Socket socket  = new Socket("130.254.204.33", 8000);
or you can you the domain name to create the socket:
Socket socket = new Socket("liang.armstrong.edu", 8000);
17
Q

How can a program refer to the machine on which a client is running?

A

A program can use the host name localhost or the IP address 127.0.0.1 to refer to the machine on which a client is running.

18
Q

How do you get an input/output stream for a socket?

A

To get an input stream and an output stream, use the getInputStream() and getOutputStream() methods on a socket object.
InputStream input = socket.getInputStream();
OutputStream output = socket.getOutputStream();

19
Q

What is the InetAddress class for?

A

The server program can use the InetAddress class to obtain the information about the IP address and host name for the client.

20
Q

How does a server handle multiple clients?

A

A server can serve multiple clients. The connection to each client is handled by one thread.

while (true)
{
    Socket socket = serverSocket.accept();
    Thread thread = new ThreadClass(socket);
    thread.start();
}
21
Q

How can you send and receive objects from another program/server?

A

As with regular I/O, you can just use ObjectOutputStream and ObjectInputStream on socket streams.

22
Q

When creating a server on a port that is already in use, ____

A. java.net.BindException occurs.
B. the server is created with no problems.
C. the server is blocked until the port is available.
D. the server encounters a fatal error and must be terminated.

A

A. java.net.BindException occurs.

23
Q

When creating a client on a server port that is already in use, ____

A. the client can connect to the server regardless of whether the port is in use.
B. java.net.BindException occurs.
C. the client is blocked until the port is available.
D. the client encounters a fatal error and must be terminated.

A

The correct answer is A
Explanation: To connect to a client, the server creates a client socket from the ServerSocket. You can create any number of client sockets on the server side to connect to a client on the Internet.

24
Q

The server listens for a connection request from a client using the following statement:

A. Socket s = new Socket(ServerName, port);
B. Socket s = serverSocket.accept()
C. Socket s = serverSocket.getSocket()
D. Socket s = new Socket(ServerName);
A

B. Socket s = serverSocket.accept()

25
Q

The client requests a connection to a server using the following statement:

A. Socket s = new Socket(ServerName, port);
B. Socket s = serverSocket.accept();
C. Socket s = serverSocket.getSocket();
D. Socket s = new Socket(ServerName);
A

A. Socket s = new Socket(ServerName, port);

26
Q

When a client requests connection to a server that has not yet started, ____

A. java.net.BindException occurs.
B. java.net.ConnectionException occurs.
C. the client is blocked until the server is started.
D. the client encounters a fatal error and must be terminated.

A

B. java.net.ConnectionException occurs.

27
Q

To connect to a server running on the same machine with the client, which of the following can be used for the hostname?

A. “localhost”
B. “127.0.0.1”
C. InetAddress.getLocalHost()
D. “127.127.127.1”

A

ABC are correct

28
Q

To create an InputStream on a socket s, you use ___

A. InputStream in = new InputStream(s);
B. InputStream in = s.getInputStream();
C. InputStream in = s.obtainInputStream();
D. InputStream in = s.getStream();
A

B. InputStream in = s.getInputStream();

29
Q

_____ models an IP address, which can be used to find the host name and IP address of the client.

A. The ServerSocket class
B. The Socket class
C. The InetAddress class
D. The Connection interface
A

C. The InetAddress class

30
Q

You can invoke ______________ on a Socket object, say socket, to obtain an InetAddress object.

A. socket.InetAddress();
B. socket.getInetAddress();
C. socket.obtainInetAddress();
D. socket.retrieveInetAddress();

A

B. socket.getInetAddress();