Академический Документы
Профессиональный Документы
Культура Документы
ASSIGNMENT SET - 01
4. How will you develop a simple web client in Java using Sockets?
Ans –
Import java.io.*;
Import java.net.*;
Public class webc
{
Public static void main (String args [ ])
{
Try
{
Socket cSock1 = new socket ( “cecasun.utc.edu”,80);
System.out.println( “client1 : “ + cSock1);
getpage (cSock1);
}
catch (UnknownhostExeception e);
System.out.println (UnknownhostExeception: “ + e);
}
catch (IOExeception e)
{
System.err.println(“IOException: “+e);
}
}
Public static void getpage (socket c sock)
{
Try
{
Dataoutputstream outbound = new dataoutputstream
( cSock.getoutputstream());
{
{
Datainputstream inbound = new datainputstream(cSock.getinputstream ());
Outbound.writebytes(“GET /~cslab/cpsc591/test.htm HTTP/1.0\r\n\r\n”);
String responseLine;
While ((responseline = inbound.readline()) !=null)
{
System.out.println (responseLine);
If (responseline.indexof(“</html>”)!=-1)
break;
}
Outbound.close( );
Inbound.close ( );
cSock.close ( );
}
Catch (IOexception ioe)
{
System.out.println (“IOException: “+ ioe);
}
}
}
5. Explain TCP/IP Protocol in detail.
Ans- TCP/IP, an acronym for transmission control protocol, corresponds to the forth layer of
OSI reference model. IP corresponds to the third layer of the some model. Each of the protocols
has the following features:
The TCP header includes both source and destination port fields for identifying the applications
for which the connection is established. The sequence and acknowledgment number fields under
the positive acknowledgement and retransmission technique. Integrity checks are accommodator
using the checksum field.
IP: In contrast to TCP, it is a connectionless type service and operates at third layer of OSI
reference model. That is prior to transmission of data, no logical connection is needed. This type
of protocol is suitable for the sporadic transmission of data to a number of destinations. This has
no functions like sequence control, error recovery and control, flow control but this identifies the
connection with port number.
ASSIGNMENT SET - 01
Two tier client server architecture: - @-tier architecture, RPC’s or SQL are typically used to
communicate between the client and server. The server is likely to have support for stored procedures
and trigger. These mean that the server can be programmed to implement business rules that are better
suited to run on the client, resulting in a much more efficient overall system.
Since 1992 software vendors have developed and brought to market
toolsets to simplify development of application for the 2-tier client/server architecture. The best
known of these tools are Microsoft’s visual basic Borland’s Delphi, and Sybase’s power Builder
These modern, powerful tools combined with literally million of developer who to use them that the
2-tiered client/server approach is a good and economical solution for certain classes of problems.
Three tier client/server architecture:- The client can deliver its request to the middle layer, disengage
and be assured that a proper response will be forthcoming at a later time. In addition, the middle layer
add synonymous in this context .There’s no free lunch, however, and the price for this added
flexibility and performance has been a development environment of 2-tiered applications.
The most part type of middle layer (and the oldest, the concept on mainframes dating from the early
1970’s) is the transaction processing monitor or TP Monitor.
TP monitor as a kind of message queuing service. The client connects to the TP monitor instead of
the database server.
The transaction is accepted by the monitor, which queues it and then takes responsibility for
managing it to correct completion.
Ans – A frequently overlooked aspect of a LAN’s topology is its connection to the wide area network.
In many cases, WAN connectivity is provided by a single connection from the backbone to the router.
WAN traffic benefit greatly from having the most robust connection possible in this aspect of
their overall topology. The technology selected should be robust in terms of its nominal
transmission rate and its access method. Connection- based media, even on a dedicated
switched port, may become problematic in high usage networks. This is the bottleneck for all
Ans: - uses a server socket to wait for a connection, then opens a socket to the client to
return an HTML document with HTTP headers.
Import java.io.*;
Import java.net.*;
Class websrv {
Public static void main (String args []) {
Serversocket srvsock = null;
Socket clisock=null;
Int connection = 0;
Try {
Srvsock = new serversocket(60337, 5);
While (connects <3) {
clisock = srvsock.accept ();
Serviceclient (clisock);
Connects++;
}
Srvsock.close();
} catch (IOException e) {
System.out.println (“error in simple webserver: “+e);
}
}
Public static void serviceclient (socket client)
Throws IOException {
Datainputstream inbound = null;
Dataoutputstream outbound = null;
Try {
Inbound = new Datainputstream (client.getinputstream());
Outbound = new Dataoutputstream (client.getoutputstream());
StringBuffer buffer = prepareoutput();
String inputLine;
While ((inputLine = inbound.readline()) !=null) {
If (inputline.equals (“”)) {
Outbound.writebytes (buffer. to string ());
System.out.println (“wrote buffer to “+ client);
//sleep (500); for slow win 95
break;
}
}
} finally {
System.out.println (“cleaning up connection: “+ client);
Outbound.close ( );
Inbound.close ( );
Client.close ( );
Client.close ( );
}
}
Public static stringbuffer prepare output ( ) {
Stringbuffer outputbuffer = newstring buffer ( );
Outputbuffer.append (“<HTML>\n<HEAD>\n<TITLE>Test HTML Document
</TITLE>\n”);
outputBuffer.append (“</HEAD>\n”);
outputBuffer.append (“</BODY>\n This is a <STRONG>test</STRONG>HTML
Document!\n” );
outputBuffer.append (“</BODY>\n”);
outputBuffer.append (“</HTML>\n”);
stringbuffer headerbuffer = new stringbuffer ( );
headerBuffer.append (“HTTP/1.0 200 ok\r\n”);
headerBuffer.append (“content.type: text/html\r\n”);
headerBuffer.append (“content-length: ” + outputbuffer.length( ));
headerBuffer.append (“\r\n\r\n”);
headerBuffer.append (“outputbuffer.tostring() );
return headerbuffer;
}
}
Qn = 1; add B 10111
The number can be represented as rk+1 – 2” = 2n-2’ = 16-2=14. Therefore, the multiplication
M*14, where M is multiplicand and 14 the multiplier, can be done as M*24 – M*2*. Thus, the
product can be obtained by shifting the binary multiplicand M four times to the left and
subtracting M shifted left once.
As in all multiplication schemes booth algorithm requires examination of the multiplier bits
and shifting of the partial product. Prior of the shifting, the multiplicand may be added to the
partial product, subtracted from the partial product, or left unchanged according to the
following rules:-
1. The multiplicand is subtracted from the partial product upon encountering the first
least significant 1 in a string of 1’s in the multiplier.
2. The multiplicand is added to the partial product upon encountering the first Q in a
string of 0’s in the multiplier.
3. The partial product does not change when the multiplier bit is identical to the previous
multiplier bit.
The algorithm works for positive or negative multipliers in 2’s complement representation.
This is because a negative multiplier ends with a string of l’s and the last operation will be a
subtraction of the appropriate weight. For example, a multiplier equal to -14 is represented in