Network Programming & Applications

quicksandwalleyeInternet and Web Development

Oct 31, 2013 (4 years and 8 months ago)


Network Programming &

Important Idea

A programmer can create Internet
application software without understanding
the underlying network technology or
communication protocols

Network Communication

Network transfers data from one point to another

The network is passive

it does not understand
the information being sent nor does it process
the information

All processing is done by application programs

Applications use the network in pairs


distributed database service that
allows remote users to access a centralized

Server Computing

One application (server) starts first and waits for
the other application to contact it

The second application (client) must know the
location where the first application is waiting

The client specifies the location on the Internet
using a pair of identifiers (computer, application)

Application software represent these two
identifiers as binary numbers

Humans use alphabetic names

Server Paradigm

Server starts first and waits for a client to
contact the server

The client specifies the server’s location
and requests a connection be established

Once the connection is established, it is
used to exchange messages

After the data is sent, the client and server
both send an end
file message to break
the connection


Application Program Interface

A set of operations available to an
application programmer

Each operation is defined as to what it

The arguments for each operation are

An API for Network Programming

Await_contact : used by server to wait for client

Make_contact : Used by client to contact server

Cname_to_comp : Used to change computer
name to binary value

Appname_to_appnum : change program name
to a binary value

Send : sends data by client or server

Recv : receive data by client or server

Send_eof : used by client and server to send eof

Intuitive Look at API in Operation

Server calls await_contact first

Client begins by calling make_contact

The two exchange messages using the
send and recv

The two applications must be programmed
to know whether to send or receive

deadlock can occur if both sides are
waiting to receive

See Figure 3.2 for a sample session

Parameters Used by the API

Appnum : a binary value used to identify
an application

Computer : a binary value used to identify
a computer

Connection : a value used to identify the
connection between client and server

Await_Contact Function

Connection await_contact (appnum a)

Server calls this function

Argument specifies the application running
on the server

A client must specify the same number
when contacting the server

The server uses the return value (type
connection) to transfer data

Make_Contact Function

Connection make_contact (computer c,
appnum a)

Client calls this function to establish
contact with server

Appname_to_appnum Function

Appnum appname_to_appnum(char *a)

Used by both client and server to translate
from a human
readable name for a service
to a binary value

Cname_to_Comp function

Computer cname_to_comp(char *c)

Clients call this function to convert from
computer name to binary value

Send Function

Int send(connection con, char *buffer, int length,
int flags)

Four arguments

Con : specifies a connection previously established

*buffer : address of a buffer containing data to send

Length : length of the data in bytes

Flags ; 0 for normal transfer

Send returns the number of bytes transferred, or
a negative value if an error occurred

Recv Function

Int recv (connection con, char *buffer, int length,
int flags)

Used by both client and server

Four arguments

Con : specifies a connection previoulsy established
with await_connection or make_connection

*buffer : address of a buffer into which the data
should be placed

Length : size of the buffer in bytes

Flag ; 0 for normal transfer

Send_eof Function

Int send_eof(connection con)

Argument con specifies a connection
previously made with await_contact or

Negative value returned to indicate that an
error occurred

negative value indicates no error

Look at code for the following


Server echoes back all the data it receives

Client repeatedly prompts user for a line of
input, sends the line to the server, and then
displays whatever the server sends back




Read (If you haven’t already done so) and
study Chapter 3 (4

Ed.) of your text

Complete Lab 4

Install Ubumtu OS