SHARE
SPREAD
HELP

The Tradition of Sharing

Help your friends and juniors by posting answers to the questions that you know. Also post questions that are not available.


To start with, Sr2Jr’s first step is to reduce the expenses related to education. To achieve this goal Sr2Jr organized the textbook’s question and answers. Sr2Jr is community based and need your support to fill the question and answers. The question and answers posted will be available free of cost to all.

 

#
Authors:
James F. Kurose, Keith W. Ross
Chapter:
Application Layer
Exercise:
Problems
Question:12 | ISBN:9780132856201 | Edition: 6

Question

Write a simple TCP program for a server that accepts lines of input from a client and prints the lines onto the server’s standard output. (You can do this by modifying the TCPServer.py program in the text) Compile and execute your program. On any other machine that contains a Web browser, set the proxy server in the browser to the host that is running your server program; also configure the port number appropriately. Your browser should now send its GET request messages to your server, and your server should display the messages on its standard output. Use this platform to determine whether your browser generates conditional GET messages for objects that are locally cached.

TextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbookTextbook

Answer


TCP Program code:

import java.io.*;

import java.net.*;


class TCPServerDemo

{

public static void main(String argv[]) throws Exception

{

String clientMessage;

ServerSocket messageSocket = new ServerSocket(6789);

while(true) {

Socket connectionSocket = messageSocket.accept();


BufferedReader bd = new BufferedReader(new InputStreamReader(

connectionSocket.getInputStream( ) ) );

clientMessage = bd.readLine();

System.out.println(“Client message recieved: ” + clientMessage + “\n”);

}

}

}


0 0

Discussions

Post the discussion to improve the above solution.