Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

CS4514 B06: TCP/IP Socket Programming - HELP Session 1, Study notes of Data Communication Systems and Computer Networks

The slides for the first help session of cs4514 b06, a course on tcp/ip socket programming at the university of texas at dallas. The session, presented by mingzhe li, covers the basics of unix network programming, tcp client and server, processing commands, and tips for finding help. The document also includes examples of tcp client and server implementation.

What you will learn

  • What are the key topics covered in CS4514 B06?
  • What are some useful system calls and programming tips provided in the document?
  • What are the different system calls for sockets in CS4514 B06?
  • What are the commands that can be processed in the client-server communication in CS4514 B06?
  • What is the purpose of Project 1 in CS4514 B06?

Typology: Study notes

2014/2015

Uploaded on 09/22/2015

unknown user
unknown user 🇦🇿

1 / 37

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
CS4514 B06
HELP Session 1
Presented by Mingzhe Li
lmz@cs.wpi.edu
CS4514 TCP/IP Socket Programming
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25

Partial preview of the text

Download CS4514 B06: TCP/IP Socket Programming - HELP Session 1 and more Study notes Data Communication Systems and Computer Networks in PDF only on Docsity!

CS4514 B

HELP Session 1

Presented by Mingzhe Li lmz@cs.wpi.edu

CS4514 – TCP/IP Socket Programming

Outline

•^

Project 1 Overview

•^

Unix Network Programming^ –

TCP Client – TCP Server

•^

Processing commands

•^

How to find help and other tips.

Project 1 missions (in handout) •^

The Client: 1.^

Reading a command from a script fileor from console.

Sending the command to the server.

Receiving and displaying theinformation from the server.

Writing the results to the log file^ LClient.log.

Project 1 missions (in handout) •^

Server:^ 1.Processing the command from the

client and return the result to the client.

2.Maintaining the records to keep the

location information.

3.Writing the complete database to the

file

LDatabase.txt

when the server

received the “quit EOF” command.

read()

connection establishment

Server (connection-oriented protocol)blocks until connection

from client

Client

socket()bind()listen()accept() read() write()

socket()connect()write()

process request

data (request)data (reply)

Socket system calls forSocket system calls forconnectionconnection-

-orientedoriented

protocol ( TCP )protocol ( TCP )

What Do We Need?

-^

Data communication between two hostson the Internet require the fivecomponents : { protocol, local-addr, local-process, foreign-addr, foreign-process

-^

The different system calls for socketsprovides values for one or more of thesecomponents.

TCP Connection (Client)

•^

Connection Oriented^ –

Specify transportaddress once atconnection

•^

Use File Operations

-^ read() / write()

or

-^ recv() / send()

•^

Reliable Protocol

socket() connect() read() / write()^ recv() /send()

close()

Example: TCP Client

int sd; struct hostent *hp;

/ /usr/include/netdb.h /

struct sockaddr_in server;

/ /usr/include/netinet/in.h /

/ prepare a socket / if ( (sd =

socket

( AF_INET, SOCK_STREAM, 0 )) < 0 ) {

perror( strerror(errno) ); exit(-1);

}

Example: TCP Client

(Continued)

/ connect to the server / if (

connect

(^ sd, (struct sockaddr*) &server, sizeof(server) ) < 0

perror( strerror(errno) ); exit(-1);

} / send/receive data / while (1) {

read/write();

} / close socket / close

( sd );

TCP Connection (Server)

•^

Bind transportaddress to socket

•^

Listen to the socket

•^

Accept connection ona new socket

socket()^ bind()^ listen() accept()^ close() read()/write()

Example: TCP Server

(Continued)

bind

( sd, (struct sockaddr*) &server, sizeof(server) ); listen

( sd, backlog ); while (1) {^ nsd =

accept

( sd, (struct sockaddr *) &client, sizeof(client) );

read

write

close( nsd ); } close( sd );

Outline

•^

Project 1 Overview

•^

Unix Network Programming^ –

TCP Client – TCP Server

•^

Processing commands

•^

How to find help and other tips.

Commands

-^

In the

login, add, remove

, and

quit

commands: The server only returns one message to the client.

-^

In the

list command,

The server could

return multiple messages to the client.^ “Each entry, which meets the search condition, is sent as aseparate

TCP message back to the Client

.”

Login Command

•^

Login Command Format.^ login

•^

Login Command Handling^ –

For The Client: When the Client reads alogin command, the client establishes aTCP connection to the Server. – For The Server: When the Serverreceives a “login”, it replies “Hello!” tothe client.