Linux Overview and Introduction To Socket Programming: Lab Instructor
Linux Overview and Introduction To Socket Programming: Lab Instructor
Lab Instructor
Syed Aftab Rashid
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
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
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)
BASIC COMMANDS
How to run commands
[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
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
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
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
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
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.
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 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
Socket API
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
network part.
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
Little Endian
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.
TCP/UDP
IP Ethernet Adapter
client can identify the server/service HTTP = 80, FTP = 21, Telnet = 23, ...
Clients
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.
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