100% found this document useful (1 vote)
135 views9 pages

Web Services and Middleware 2.1 Web Services and Middleware

This document discusses network programming concepts such as web services, middleware, and low-level data communications. It specifically covers web service architecture including how clients find and bind services via WSDL and SOAP over HTTP. It also covers basic network concepts like packets, protocols, ports, IP addresses, and client-server computing. UDP and TCP are described as common network protocols used with sockets for client-server communication. Creating UDP servers and clients in Java using DatagramSockets and DatagramPackets is also summarized.

Uploaded by

Eric Gabrielson
Copyright
© © All Rights Reserved
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
100% found this document useful (1 vote)
135 views9 pages

Web Services and Middleware 2.1 Web Services and Middleware

This document discusses network programming concepts such as web services, middleware, and low-level data communications. It specifically covers web service architecture including how clients find and bind services via WSDL and SOAP over HTTP. It also covers basic network concepts like packets, protocols, ports, IP addresses, and client-server computing. UDP and TCP are described as common network protocols used with sockets for client-server communication. Creating UDP servers and clients in Java using DatagramSockets and DatagramPackets is also summarized.

Uploaded by

Eric Gabrielson
Copyright
© © All Rights Reserved
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/ 9

Integrative programming and technologies

Chapter 2
Web Services and Middleware; Network programming; Message
and queuing services; Low level data communications
2.1 Web Services and Middleware
Web services:
Web Services is an application integration technology.
Web Services allow applications to be integrated more rapidly,
easily and less expensively. The Web did for program-to-user
interactions; Web Services are developed for program-to-
program interactions. Web Services allow companies to reduce
the cost of doing e-business, to deploy solutions faster and
to open up new opportunities. Web services model built on
existing and emerging standards such as HTTP, Extensible
Markup Language (XML), Simple Object Access Protocol (SOAP),
Web Services Description Language (WSDL) and Universal
Description, Discovery and Integration (UDDI).
 XML Web Services expose useful functionality to Web users
through a standard Web protocol. In most cases, the protocol
used is SOAP.
 XML Web services provide a way to describe their interfaces
in enough detail to allow a user to build a client
application to talk to them. This description is usually
provided in an XML document called a Web Services
Description Language (WSDL) document.
 XML Web services are registered so that potential users can
find them easily. This is done with Universal Discovery
Description and Integration (UDDI).
Web service is developed in order to distribute an object
and serve it to various users in the web environments. It can
be also used in the server situations while solving the web-
scalability problem of the other distributed object
technologies. Fig.2.1 demonstrates the web service
architecture.

Figure.2.1. Web service architecture

1 ||By:Beya
Integrative programming and technologies

1. A client that wants to be serviced should first find the


supported services from the pre-existing registry before
compiling a code.
2. After finding its services through searching, the client gains
the Web Service Description Language (WSDL) that a server
previously registers. From the WSDL, the client knows the
service provider location and the parameters to the found
method.
3. After the client binds the described service during the
compile time, it calls the local agent whenever the client
invokes a method call, and the local agent delivers it to the
server side agent through Simple Object Access Protocol (SOAP)
over HTTP, FTP, SMTP, IIOP, and TCP during the runtime.
4. The server side agent activates the appropriate object, and
delivers the calls to the object.
All of the communication methods such as a WSDL, and
SOAP exploit the eXtensible Markup Language (XML). WSDL is an
XML describing the web service. SOAP is an XML describing the
called method, its parameters, and its return value, can be
delivered over the HTTP.

2.2 Network Programming


2.2.1 Basic Network Concepts
Network:
• A network is a collection of computers and other devices
that can send data to and receive data from each other.
• A network is often connected by wires.
• However, wireless networks transmit data through infrared
light and microwaves.
Node:
• Each machine on a network is called a node.
• Most nodes are computers, but printers, routers, bridges,
gateways etc..can also be nodes.
• Nodes that are fully functional computers are also called
hosts.
Packet:
• All modern computer networks are packet-switched networks:
data traveling on the network is broken into chunks called
packets and each packet is handled separately.
• Each packet contains information about who sent it and where
it's going.
Protocol:

2 ||By:Beya
Integrative programming and technologies

• A protocol is a precise set of rules defining how computers


communicate: the format of addresses, how data is split into
packets, and so on.
• There are many different protocols defining different
aspects of network communication.
IP:
• IP was designed to allow multiple routes between any two
points and to route packets of data around damaged routers.
TCP:
• Since there are multiple routes between two points, and
since the quickest path between two points may change over
time as a function of network traffic and other factors),
the packets that make up a particular data stream may not
all take the same route.
• Furthermore, they may not arrive in the order they were
sent, if they even arrive at all.
UDP:
• UDP is an unreliable protocol that does not guarantee that
packets will arrive at their destination or that they will
arrive in the same order they were sent.
Ports:
• Each computer with an IP address has several thousand
logical ports.
• Each port is identified by a number between 1 and 65,535.
Each port can be allocated to a particular service.
• Port numbers 1 through 255 are reserved by IP for well-known
services. A well-known service is a service that is widely
implemented which resides at a published, "well-known",
port. If you connect to port 80 of a host, for instance, you
may expect to find an HTTP server.
2.2.2 Network Programming Concepts:
Internet:
The Internet is the world's largest IP-based network. The
Internet is all about connecting machines together. One of the
most exciting aspects of Java is that it incorporates an easy-
to-use, cross-platform model for network communications.
What is a Socket?
Sockets are a means of using IP to communicate between
machines, so sockets are one major feature that allows Java to
interoperate with legacy systems by simply talking to existing
servers using their pre-defined protocol.
Other common protocols are layered on top of the Internet
protocol: User Datagram Protocol (UDP) and Transmission

3 ||By:Beya
Integrative programming and technologies

Control Protocol (TCP). Applications can make use of these two


protocols to communicate over the network.
Internet Addresses or IP Addresses
Every network node has an address, a series of bytes that
uniquely identify it. Internet addresses are manipulated in
Java by the use of the InetAddress class.InetAddress takes
care of the Domain Name System (DNS) look-up and reverselook-
up; IP addresses can be specified by either the host name or
the raw IPaddress. InetAddress provides methods to
getByName(), getAllByName(),getLocalHost(), getAddress(), etc.
IP addresses are a 32-bit number, often represented as a
"quad" of four 8-bitnumbers separated by periods. They are
organized into classes (A, B, C, D, and E). Forexample
126.255.255.255

Client/Server Computing
You can use the Java language to communicate with remote file
systems using aclient/server model. A server listens for
connection requests from clients acrossthe network or even
from the same machine. Clients know how to connect to
theserver via an IP address and port number. Upon connection,
the server reads therequest sent by the client and responds
appropriately. In this way, applicationscan be broken down
into specific tasks that are accomplished in
separatelocations.
The data that is sent back and forth over a socket can be
anything you like.Normally, the client sends a request for
information or processing to the server,which performs a task
or sends data back. The IP and port number of the server is
generally well-known and advertised sothe client knows where
to find the service.
How UDPclients and UDPservers communicate over sockets
Creating UDP Servers:
To create a server with UDP, do the following:
1. Create a DatagramSocket attached to a port.
int port = 1234;
DatagramSocket socket = new DatagramSocket(port);
2. Allocate space to hold the incoming packet, and create an
instance ofDatagramPacket to hold the incoming data.
byte[] buffer = new byte[1024];
DatagramPacket packet =new DatagramPacket(buffer,
buffer.length);
3. Block until a packet is received, then extract the
information you need from thepacket.

4 ||By:Beya
Integrative programming and technologies

// Block on receive()
socket.receive(packet);
// Find out where packet came from
// so we can reply to the same host/port
InetAddressremoteHost = packet.getAddress();
intremotePort = packet.getPort();
// Extract the packet data
byte[] data = packet.getData();
The server can now process the data it has received from the
client, and issue anappropriate reply in response to the
client's request.
Creating UDP Clients
Writing code for a UDP client is similar to what we did for a
server. Again, weneed a DatagramSocket and a DatagramPacket.
The only real difference is thatwe must specify the
destination address with each packet, so the form of
theDatagramPacket constructor used here specifies the
destination host and portnumber. Then, of course, we initially
send packets instead of receiving.
1. First allocate space to hold the data we are sending and
create an instance ofDatagramPacket to hold the data.
byte[] buffer = new byte[1024];
int port = 1234;
InetAddress host =InetAddress.getByName("magelang.com");
DatagramPacket packet =new DatagramPacket(buffer,
buffer.length,host, port);
2. Create a DatagramSocket and send the packet using this
socket.
DatagramSocket socket = new DatagramSocket();
socket.send(packet);
The DatagramSocket constructor that takes no arguments will
allocate a free localport to use. You can find out what local
port number has been allocated for yoursocket, along with
other information about your socket if needed.
// Find out where we are sending from
InetAddresslocalHostname = socket.getLocalAddress();
intlocalPort = socket.getLocalPort();
The client then waits for a reply from the server. Many
protocols require theserver to reply to the host and port
number that the client used, so the client cannow invoke
socket.receive() to wait for information from the server.
How TCPclients and TCPservers communicate over sockets
Creating TCP Servers:
To create a TCP server, do the following:

5 ||By:Beya
Integrative programming and technologies

1. Create a ServerSocket attached to a port number.


ServerSocket server = new ServerSocket(port);
2. Wait for connections from clients requesting connections to
that port.
// Block on accept()
Socket channel = server.accept();
You'll get a Socket object as a result of the
connection.
3. Get input and output streams associated with the socket.
out = new PrintWriter(channel.getOutputStream());
reader = new InputStreamReader(channel.getInputStream());
in = new BufferedReader (reader);
Now you can read and write to the socket, thus,
communicating with the client.
String data = in.readLine();
out.println("Hey! I heard you over this socket!");
When a server invokes the accept() method of the ServerSocket
instance, themain server thread blocks until a client connects
to the server; it is then preventedfrom accepting further
client connections until the server has processed the
client'srequest. This is known as an iterative server, since
the main server method handleseach client request in its
entirety before moving on to the next request.
Iterativeservers are good when the requests take a known,
short period of time. Forexample, requesting the current day
and time from a time-of-day server.
Creating TCP Clients:
To create a TCP client, do the following:
1. Create a Socket object attached to a remote host, port.
Socket client = new Socket(host, port);
When the constructor returns, you have a connection.
2. Get input and output streams associated with the socket.
out = new PrintWriter(client.getOutputStream());
reader = new InputStreamReader(client.getInputStream());
in = new BufferedReader (reader);
Now you can read and write to the socket, thus,
communicating with the server.
out.println("Watson!" + "Come here...I need you!");
String data = in.readLine();
2.4 Low Level Data Communication
Data communications are the exchange of data between two
devices via some form of transmission medium such as a wire
cable.
TCP/IP(Transmission Control Protocol/Internet Protocol)

6 ||By:Beya
Integrative programming and technologies

 The Protocol upon which the whole Internet is based


– Each node must be configured for TCP/IP to function
properly.
 A software-based protocol
 TCP/IP is basically the binding together of Internet
Protocols used to connect hosts on the internet- Main ones
are IP and TCP
 TCP and IP have special packet structure
 IP (Internet Protocol) is responsible for delivering packets
of data between systems on the internet and specifies their
format. Packets forwarded based on a four byte destination
IP address (IP number)
 IP DOES NOT MAKE GUARANTEES! It is very simple -
essentially: send and forget.
 TCP (Transmission Control Protocol) is responsible for
verifying the correct delivery of data/packets from client
to server. Data can be lost - so TCP also adds support to
detect errors and retransmit data until completely
received.
 Together these help form TCP/IP - a means of specifying
packets, and delivering them safely.
 There are other protocols in TCP/IP - such as User Datagram
Protocol UDP. UDP is a simpler alternative to TCP for aiding
the delivery of packets. It makes no guarantees regarding
delivery - but does guarantee data integrity. UDP also has
no flow control, i.e. if messages are sent too quickly, data
may be lost
2.4.1 IP Packet Structure

7 ||By:Beya
Integrative programming and technologies

Figure.2.2. IP Packet Structure


IP uses a Datagram to transfer packets between end systems
(usually computers) using routers. There are fourteen fields
in an IP Packet .
Version — Indicates the version of IP currently used.
IP Header Length (IHL) — Indicates the datagram header length
in 32-bit words.
Type-of-Service — Specifies how an upper-layer protocol would
like a current datagram to be handled, and assigns datagram
various levels of importance.
Total Length — Specifies the length, in bytes, of the entire
IP packet, including the data and header.
Identification — Contains an integer that identifies the
current datagram. This field is used to help piece together
datagram fragments.
Flags — Consists of a 3-bit field of which the two low-order
(least-significant) bits control fragmentation. The low-order
bit specifies whether the packet can be fragmented. The middle
bit specifies whether the packet is the last fragment in a
series of fragmented packets. The third or high-order bit is
not used.
Fragment Offset — Indicates the position of the fragment’s
data relative to the beginning of the
data in the original datagram, which allows the destination IP
process to properly reconstruct
the original datagram.
Time-to-Live — Maintains a counter that gradually decrements
down to zero, at which point the
datagram is discarded. This keeps packets from looping
endlessly.
Protocol — Indicates which upper-layer protocol receives
incoming packets after IP processing is complete.
Header Checksum — Helps ensure IP header integrity.
Source Address — Specifies the sending node.
Destination Address — Specifies the receiving node.
Options — Allows IP to support various options, such as
security.
Data — Contains upper-layer sent in packet.
2.4.2 TCP Packet Structure:

8 ||By:Beya
Integrative programming and technologies

Figure.2.2. TCP Packet Structure

There are 12 fields in TCP Packet:


Source Port and Destination Port— Identifies points at
whichupper-layer source and
destination processes receiveTCP services.
Sequence Number — Usuallyspecifies the number assignedto the
first byte of data inthe current message. In theconnection-
establishment phase,this field also can be used toidentify an
initial sequencenumber to be used in anupcoming transmission.
Acknowledgment Number —Contains the sequence number ofthe next
byte of data the sender
of the packet expects to receive.
Data Offset — Indicates the number of 32-bit words in the TCP
header.
Reserved — Remains reserved for future use.
Flags — Carries a variety of control information, including
the SYN and ACK bits used for connection
establishment, and the FIN bit used for connection
termination.
Window — Specifies the size of the sender’s receive window
(that is, the buffer space available for
incoming data).
Checksum — Indicates whether the header was damaged in
transit.
Urgent Pointer — Points to the first urgent data byte in the
packet.
Options — Specifies various TCP options.
Data — Contains upper-layer sent in packet.

9 ||By:Beya

You might also like