0% found this document useful (0 votes)
84 views1 page

Exercises Networking Servers

The document describes several networking exercises to create Java server and client programs: 1. Create a server that sends a random number to any client that connects. Test it from a web browser and telnet client. Also create a Java client that connects and prints the number. 2. Create a server that takes two numbers from a client, adds them together, and returns the sum. Test it with telnet. Create a client that takes inputs from the command line and uses the addition server to sum the numbers. 3. Create a multithreaded version of the addition server by copying and renaming the MultithreadedServer and ConnectionHandler classes and moving the networking code to the ConnectionHandler run method.

Uploaded by

Szabó Attila
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
84 views1 page

Exercises Networking Servers

The document describes several networking exercises to create Java server and client programs: 1. Create a server that sends a random number to any client that connects. Test it from a web browser and telnet client. Also create a Java client that connects and prints the number. 2. Create a server that takes two numbers from a client, adds them together, and returns the sum. Test it with telnet. Create a client that takes inputs from the command line and uses the addition server to sum the numbers. 3. Create a multithreaded version of the addition server by copying and renaming the MultithreadedServer and ConnectionHandler classes and moving the networking code to the ConnectionHandler run method.

Uploaded by

Szabó Attila
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Customized Onsite Training: Java 7, JSF 2, PrimeFaces, Servlets/JSP, Ajax/jQuery, Android, Spring, Hibernate, Hadoop, GWT, REST, etc:

http://courses.coreservlets.com/

Network Servers
Note: again, there is no need to use my NetworkServer class for these exercises; you could easily write everything from scratch. Using NetworkServer will just save you a few lines of code. If you do use it, you would need to copy NetworkServer.java and SocketUtil.java into your Eclipse project, then do something like this:
public class MyServer extends NetworkServer { public MyServer(int port) { super(port); }

public void handleConnection(Socket s) throws IOException { // This is the main code you need to write } }

Then, your driver routine (the one that has main) would do:
MyServer server = new MyServer(some-port); server.listen(); // Start listening for incoming connections

1. 2. 3.

Make a server that sends a random number to anyone that connects to it. Connect to it from a Web browser. Also connect to it using telnet. (Open a DOS window and type telnet localhost portnumber. Kill telnet by hitting Control-] and then entering Quit.) Make a Java client program that connects to it and prints out the number that is sent. (Hint: you may have already written this in your solutions to the networking clients exercises.) Make a server that takes two numbers on separate lines, adds them together, and returns the sum. (Recall that Double.parseDouble will turn a String into a double). Test with telnet, but note that you will have to type blind because the Windows telnet client does not echo the characters you type by default. Linux and MacOS telnet clients do echo properly, but even on Windows this is a useful way to test. Make a client that takes a host, port, and two numbers from the command line, uses the addition server to sum the two numbers, and prints the result. Make a multithreaded version of your SumServer. Your networking code will be the same in both cases, but where you put it will be different. Start by copying and renaming the MultithreadedServer and ConnectionHandler classes, then call the appropriate networking code from the run method of your renamed ConnectionHandler. Reminder: you rename a class in Eclipse by right-clicking on the classname at the left side (or selecting the name within the editor, then right-clicking), then doing Refactor --> Rename.

4. 5.

You might also like