0% found this document useful (0 votes)
57 views

Linux Overview and Introduction To Socket Programming: Lab Instructor

LAB 1 Linux overview and Introduction to Socket Programming Lab Instructor Syed Aftab Rashid Office Hours: be attentive in class and always expect a quiz. There will be no re-evaluation for any marks, whatever Circumstances are. Follow your SLATE and report your query in time otherwise don"t complain.

Uploaded by

Umar Riaz
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
57 views

Linux Overview and Introduction To Socket Programming: Lab Instructor

LAB 1 Linux overview and Introduction to Socket Programming Lab Instructor Syed Aftab Rashid Office Hours: be attentive in class and always expect a quiz. There will be no re-evaluation for any marks, whatever Circumstances are. Follow your SLATE and report your query in time otherwise don"t complain.

Uploaded by

Umar Riaz
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 35

LAB 1

Linux overview and Introduction to Socket Programming

Lab Instructor
Syed Aftab Rashid

Email: [email protected] Office: Room#316-B

Office Hours:

Be attentive in class and always expect a quiz. There will be no retake of any quiz/activity, whatever Circumstances are. Strictly follow your deadlines otherwise be ready for penalties. Follow your SLATE and report your query in time otherwise dont complaint.

There will be no re-evaluation for any marks, when report time is over. If You dont want to study Leave the Class let others Study. You will be given zero (negative marks) for copy cases (Both parties) The BIG O Concept.

Outline
1.

2.
3. 4.

5.
6. 7.

Overview of Linux System Basic Commands Relative & Absolute Path Redirect, Append and Pipe Permission Process Management Introduction to Socket Programming

OVERVIEW OF UNIX SYSTEM


Kernel & Shell

Unix/Linux is operating system (OS). Unix system is described as kernel & shell.
Kernel is a main program of Unix system. it controls hardwares, CPU, memory, hard disk, network card etc. Shell is an interface between user and kernel. Shell interprets your input as commands and pass them to kernel. User
input

Shell
Kernel

UNIX OVERVIEW (CONT.)


Directory Structure

Files are put in a directory. All directories are in a hierarchical structure (tree structure). User can put and remove any directories on the tree. Top directory is /, which is called slash or root. Users have the own directory. (home directory)

UNIX OVERVIEW (CONT.)


Directory Structure

UNIX OVERVIEW (CONT.)


Normal user and Super user In Unix system, there is one special user for administrator, which can do anything. This special user is called root or superuser. Case Sensitivity Unix is case-sensitive. MYFILE.doc, Myfile.doc, mYfiLe.Doc are different. Online Manual Unix has well-written online manuals.

BASIC COMMANDS
How to run commands

Finder => Application => Utilitaires => Terminal

When you log on Unix machine, you will see,

[someone]$

One command consists of three parts, i.e. command name, options, arguments.

Example)
[someone~]$ command-name optionA optionB argument1 argument2

BASIC COMMANDS
How to run commands

Between command name, options and arguments, space is necessary. Opitions always start with - Example: cd .. ls l .bashrc mv fileA fileB

BASIC COMMANDS
Commands

ls cd cp mv rm pwd mkdir rmdir less, more, cat man


whatis

show files in current position change directory copy file or directory move file or directory remove file or directory show current position create directory remove directory display file contents command read the online manual page for a command give brief description of a command

BASIC COMMANDS
Commands

su passwd useradd userdel mount umount df shutdown

switch user change password create new user account delete user account mount file system unmount file system show disk space usage reboot or turn off machine

Relative and Absolute path Absolute path

Address from the root /home/linux/ ~/linux ~: ~: Alt+N Similar to: Lausanne University/Lausanne/Canton de Vaud/ Switzerland/Europe/Earth/Solar System/

Relative path

Relative to your current location . : your current location .. : one directory above your current location pwd: gives you your current location
Example
ls ./linux : lists the content of the dir linux ls ../../ : lists everything that is two dir higer

Similar to: Go Left/turn right/take the TSOL/go

Redirect, append and pipe


Redirect and append

Output of command is displayed on screen. Using >, you can redirect the output from screen to a file. Using >> you can append the output to the bottom of the file.

Pipe

Some commands require input from a file or other commands. Using |, you can use output from other command as input to the command. On MacOSX, The Pipe sign: (Shift+Alt+N: franc, Alt+7)

PERMISSION

All of files and directories have owner and permission. There are three types of permission, readable, writeable and executable. Permissions are given to three kinds of group. owner, group member and others.

Example:
ls -l .bash_profile -rw-r--r-

1 cnotred

cnotred

191 Jan 4 13:11 .bash_profile

r:readable, w:writable, x: executable

PERMISSION
Command

chmod chown

change file mode, add or remove permission change owner of the file

Example) chmod a+w filename add writable permission to all users chmod o-x filename remove executable permission from others chmod a+x Gives permission to the usser to execute a file

u: user (owner),

g: group,

o: others

a: all

PROCESS MANAGEMENT

Process is a unit of running program. Each process has some information, like process ID, owner, priority, etc.

Example) Output of top command

PROCESS MANAGEMENT
Commands kill

killall ps top

Stop a program. The program is specified by process ID. Stop a program. The program is specified by command name. Show process status Show system usage statistics

What is a Computer Network?


A computer network, or simply a network, is a collection of computers and other hardware components interconnected by communication channels that allow sharing of resources and information

What is a Socket?

A socket is an abstract representation of a communication endpoint. A way to speak to other programs using standard Unix file descriptors. File descriptor is an integer associated with an open file File can be a Network connection, pipe or terminal. Everything in Unix is file Communication with other programs over internet is through File descriptor i.e Socket

Interface That OS provides to its networking Subsystem is called Application Programming Interface Socket Interface is Supported in all popular Operating Systems

Client-Server Model
In the socket programming world almost all communication is based on the Client-Server model.
Server Is a Passive Entity , Waits for clients Requests Client Is a Active Entity, Forwards its request to Server and waits for response

Server and Client exchange messages over the network through a common Socket API
Clients
Server ports
user space

TCP/UDP IP Ethernet Adapter

Socket API

TCP/UDP IP Ethernet Adapter

kernel space

hardware

An Internet Protocol address (IP address) is a numerical label assigned to each device (e.g., computer, printer) participating in a computer network that uses the Internet Protocol for communication

IPv4

IPv6

32-bit Address made up of four bytes. Consist of host part and

network part.

192.0.111.123 Three Classes A, B , C

2001:0db8:c9d2:0012:0 000:0000:0000:0051 IPv4 compatibility ::ffff:192.0.2.33

79 MILLION BILLION TRILLION Addresses 128-bit address space

Byte ordering or Endianess is the attribute of a system which indicates whether integers are stored / represented left to right or right to left. Example 1: short int x = 0xAABB (hex) This can be stored in memory as 2 adjacent bytes as either (0xaa , 0xbb) or as (0xbb, 0xaa). Big Endian: Byte Value : Memory : Little Endian: Byte Value : Memory : [0xBB] [0xAA] [ 0 ][ 1 ] [0xAA] [0xBB] [ 0 ][ 1 ]

Big Endian

c[0] c[1] c[2] c[3]


128 2 194 95

Little Endian

Most Significant byte first Network byte order


Least Significant byte first Host byte order

95

194

128

All Network data is sent in Big Endian format. In the networking world we call this representation as Network Byte Order and native representation on the host as Host Byte Order. We convert all data into Network Byte Order before transmission.

Concept of Port Numbers


Port numbers are used to identify entities on a host A socket provides an interface to send data to/from the network through a port Port numbers can be
Well-known

SSH Web daemon server


port 22 port 80

Servers/daemons usually use well-known ports


Any

(port 0-1023) Dynamic or private (port 1024-65535)

TCP/UDP
IP Ethernet Adapter

Clients usually use dynamic ports


Assigned

client can identify the server/service HTTP = 80, FTP = 21, Telnet = 23, ...

by the kernel at run time

Telephone Call Professors at FAST


285-6930 ext.102 285-6930 ext. 103

Network Programming Applications/Servers


Web Port 80 Mail Port 25

Extension Telephone No Central Number Exchange Area Code


Students

Port No. IP Address Network No. Host Number

Clients

A telephone call over a telephony network works as follows:


Both parties have a telephone installed. A phone number is assigned to each telephone. Turn on ringer to listen for a caller. Caller lifts telephone and dials a number. Telephone rings and the receiver of the call picks it up. Both Parties talk and exchange data. After conversation is over they hang up the phone.

A network application works as follows:

An endpoint (telephone) for communication is created on both ends. An address (phone no) is assigned to both ends to distinguish them from the rest of the network. One of the endpoints (caller) initiate a connection to the other. The other end (receiver) point waits for the communication to start. Once a connection has been made, data is exchanged (talk). Once data has been exchanged the endpoints are closed (hang up).

Socket() Endpoint for communication Bind() - Assign a unique telephone number. Listen() Wait for a caller. Connect() - Dial a number. Accept() Receive a call. Send(), Recv() Talk. Close() Hang up.

END

You might also like