Без темы
<<  Sociology 2: Class 17: Globalization, Culture, Identity Soil Erosion in Nepal  >>
Why does one need sockets
Why does one need sockets
Using a Stream Socket
Using a Stream Socket
Картинки из презентации «Socket Programming: a Primer» к уроку английского языка на тему «Без темы»

Автор: Linhai He. Чтобы познакомиться с картинкой полного размера, нажмите на её эскиз. Чтобы можно было использовать все картинки для урока английского языка, скачайте бесплатно презентацию «Socket Programming: a Primer.ppt» со всеми картинками в zip-архиве размером 67 КБ.

Socket Programming: a Primer

содержание презентации «Socket Programming: a Primer.ppt»
Сл Текст Сл Текст
1Socket Programming: a Primer. 14A Quick Summary: Stream. server.
2Why does one need sockets? client. socket(). bind() to a receiving
application. network. network protocol. port. listen () to socket. accept ()
Feb. 23, 2001. EE122, UCB. 2. connection. send () recv (). connect () To
3So what exactly does a socket do? It server. bind() to any port. send () recv
is an API between applications and network (). socket(). Feb. 23, 2001. EE122, UCB.
protocol software Functions it provides: 14.
Define an “end-point” for communication 15Sample Codes: Datagram Client.
Initiate and accept a connection Send and #include <sys/types.h> #include
receive data Terminate a connection <sys/socket.h> #include
gracefully Supports multiple protocol <netinet/in.h> #include
families Examples: Unix inter-process <netdb.h> #define Bfsize 1024
communication, TCP/IP Only Internet main(int argc, char *argv[]) { int sock;
sockets will be covered in this lecture. struct sockaddr_in client, server; struct
Feb. 23, 2001. EE122, UCB. 3. hostent *host, *gethostname();
4Types of Sockets. Two different types sock=socket(AF_INET, SOCK_DGRAM, 0); /*
of sockets: stream vs. datagram Stream open socket */ client.sin_family=AF_INET;
socket: (a.k.a. connection-oriented client.sin_addr.s_addr=htonl(INADDR_ANY);
socket) It provides reliable, connected /* local addr */ client.sin_port=htons(0);
networking service Error free; no /* any port # */ bind(sock,(struct
out-of-order packets (uses TCP) sockaddr *)&client,sizeof(client));
applications: telnet, http, … Datagram Feb. 23, 2001. EE122, UCB. 15.
socket: (a.k.a. connectionless socket) It 16Sample Code: Datagram Client. Don’t
provides unreliable, best-effort forget error handling when calling these
networking service Packets may be lost; functions in your programs!
may arrive out of order (uses UDP) host=gethostbyname(argv[1]); /* get host
applications: streaming audio/video, … name */ memcpy((char
Feb. 23, 2001. EE122, UCB. 4. *)&server.sin_addr, (char
5How should one define a socket? To *)host->h_addr, host->h_length);
define an end-point of communication, one server.sin_family=AF_INET;
needs to specify the family of protocol it server.sin_port=htons(atoi(argv[2]));
uses (Internet vs. others) addressing sendto(sock,msg,sizeof(msg),0,(struct
information (IP address + port number) the sockaddr *)&server, sizeof(server));
type of service it provides (stream vs. close(sock); }. Feb. 23, 2001. EE122, UCB.
datagram) Done in three steps create a 16.
socket define address and port number 17Sample Code: Datagram Server. #include
associate address with the socket. Feb. <sys/types.h> #include
23, 2001. EE122, UCB. 5. <sys/socket.h> #include
6How to create a socket? Notice that <netinet/in.h> #include
the socket descriptor is just a regular <netdb.h> #define Bfsize 1024
int ! So it has the same usage as a file main(int argc, char *argv[]) { int sock,
descriptor in Unix… # include length, count; struct sockaddr_in server,
<sys/types.h> # include client; char buffer[Bfsize];
<sys/socket.h> int sock; sock = sock=socket(AF_INET, SOCK_DGRAM,0);
socket (AF_INET, SOCK_STREAM, 0); /* for server.sin_family=AF_INET;
stream */ sock = socket (AF_INET, server.sin_addr.s_addr=htonl(INADDR_ANY);
SOCK_DGRAM, 0); /* for datagram */. Feb. server.sin_port=htons(atoi(argv[1])); /*
23, 2001. EE122, UCB. 6. listening port */ bind(sock,(struct
7How to define address? struct sockaddr sockaddr *)&server,sizeof(server));
{ u_short sa_family; char sa_data[14]; }. Feb. 23, 2001. EE122, UCB. 17.
Feb. 23, 2001. EE122, UCB. 7. 18Sample Code: Datagram Server.
8Bind a Socket. bind( ): associate a count=recvfrom(sock, buffer, Bfsize, 0,
socket descriptor with an address putting (struct sockaddr
everything together. int bind (int sockfd, *)&client,&length);
struct sockaddr *addr, int len); int printf("---> %s\n", buffer);
sockfd; struct sockaddr_in addr; close(sock); }. Feb. 23, 2001. EE122, UCB.
sockfd=socket(AF_INET,SOCKE_STREAM, 0); 18.
addr.sin_family=AF_INET; 19Sample Code: Stream Client. #include
addr.sin_port=htons(5000); /* 0: randomly <sys/types.h> #include
assigned by OS */ <sys/socket.h> #include
addr.sin_addr.s_addr=htonl(INADDR_ANY); /* <netinet/in.h> #include
local address */ <netdb.h> #define msg “hello ee122“
bzero(&(addr.sin_zero),8); /* pad main(int argc, char *argv[]) { int sock;
zeros */ bind(sockfd,(struct sockaddr struct sockaddr_in client, server; struct
*)&addr, sizeof(struct sockaddr)); hostent *host, *gethostname();
Feb. 23, 2001. EE122, UCB. 8. host=gethostbyname(argv[1]); memcpy((char
9How to convert addresses? You also *)&server.sin_addr,(char
need to define address for the other end *)host->h_addr,host->h_length);
If you know its IP address server.sin_family=AF_INET;
addr.sin_addr.s_addr=inet_addr(“128.32.138 server.sin_port=htons(atoi(argv[2])); /*
240”); If you know its name only: need to no bind is needed! */ sock=socket(AF_INET,
perform a DNS lookup. struct hostent SOCK_STREAM,0); connect(sock,(struct
*gethostbyname(char *name). struct hostent sockaddr *)&server, sizeof(server));
{ char *h_name; char **h_aliases; int Feb. 23, 2001. EE122, UCB. 19.
h_addrtype; int h_length; char 20Sample Code: Stream Client.
**h_addr_list; #define h_addr send(sock,msg,sizeof(msg),0); close(sock);
h_addr_list[0] }. Feb. 23, 2001. EE122, }. Feb. 23, 2001. EE122, UCB. 20.
UCB. 9. 21Sample Code: Stream Server. #include
10Using a Datagram Socket. Sending data <sys/types.h> #include
int sendto(int sockfd, void *msg, int <sys/socket.h> #include
msg_len, u_short flags, struct sockaddr <netinet/in.h> #include
*dest, int dest_len); Receiving data int <netdb.h> #define Bfsize 1024
recvfrom(int sockfd, void *msg, int main(int argc, char *argv[]) { int
msg_len, u_short flags, struct sockaddr new_sock, sock, length, count; struct
*src, int src_len); Feb. 23, 2001. EE122, sockaddr_in server, client; struct hostent
UCB. 10. *host, *gethostbyname(); char
11Using a Stream Socket. establishing a buffer[Bfsize]; sock=socket(AF_INET,
connection. server. client. listen (). int SOCK_STREAM,0); server.sin_family=AF_INET;
listen(int sockfd, int backlog); int server.sin_addr.s_addr=htonl(INADDR_ANY);
connect(int sockfd, struct sockaddr *addr, server.sin_port=htons(atoi(argv[1]));
int addr_len); int accept(int sockfd, void bind(sock, (struct sockaddr *)&server,
*addr, int *addrlen ); Feb. 23, 2001. sizeof(server)); listen(sock,1); Feb. 23,
EE122, UCB. 11. 2001. EE122, UCB. 21.
12Using a Stream Socket (contd). Sending 22Sample Code: Stream Server. new_sock =
data int send(int sockfd, void *msg, int accept(sock,(struct sockaddr
msg_len, u_short flags); Receiving data *)&client,&length);
int recv(int sockfd, void *msg, int count=recv(new_sock,buffer,Bfsize,0);
msg_len, u_short flags); Notice that no printf("---> %s\n", buffer);
address is required! Feb. 23, 2001. EE122, close(new_sock); close(sock); }. Feb. 23,
UCB. 12. 2001. EE122, UCB. 22.
13A Quick Summary: Datagram. server. 23Further Reading. W. Richard Stevens.
client. socket() to create socket. bind() Unix Network Programming, Prentice Hall.
to a receiving port. recvfrom() sendto (). The Unix Socket FAQ.
recvfrom() sendto (). socket() to create http://www.ibrado.com/sock-faq. Feb. 23,
socket. bind() to any port. Feb. 23, 2001. 2001. EE122, UCB. 23.
EE122, UCB. 13.
Socket Programming: a Primer.ppt
http://900igr.net/kartinka/anglijskij-jazyk/socket-programming-a-primer-60718.html
cсылка на страницу

Socket Programming: a Primer

другие презентации на тему «Socket Programming: a Primer»

«Welcome to London» - Вест Энд. Лондон. Сити. Ист Энд. The West End. The East End. Welcome to London. Westminster. Restaurant. The flag of the UK. Big Ben. Westminster Abbey. The House of Parliament. Flag. Флаг Великобритании. The city. St. Paul Cathedral. Вестминстер. London.

«ИКТ в английском языке» - Открытые уроки по английскому языку. Использование ИКТ в работе классного руководителя. Парламентские уроки. Мониторинг успеваемости. Составление диаграмм успеваемости. Прослеживание оценок. Совет Лицеистов. Электронное образование. Электронное порфолио ученика. Волонтёры. Конференция. Общественная деятельность.

«Sports in England» - Чемпионы прошлых лет. Регби на школьном стадионе. Игры. Разработать проект. Спорт в школах. Футбол. Олимпийские чемпионы Британии. Football. Снукер. Теннис. Крикет. Олимпийские чемпионы. Cricket. Sports play an important part in the life of Britain. Национальные виды спорта Великобритании. Олимпийская Англия.

«Shakespeare» - NEW YORK. THE HOUSE WAS DESTROYED. W. SHAKESPEARE («AS YOU LIKE IT»). Where was he buried? BIOGRAPHY. Family life. When and where did W.Shakespeare live? His father was a glove-maker. W. SHAKESPEARE’S SCHOOL IN STRATFORD-UPON-AVON. GARDENS OF NEW PLACE. Why did he become famous? 1623. STRATFORD ON AVON.

«Russia» - The sculpture "the native land calls mother“ in Volgograd. Russia is the secular state. Monument «the tsar of a down» in Moscow. Monument Petr to the first "the copper horseman" in Sankt-Peterburge. Welcome to Russia. Monument a «Millenium Russia» in Novgorod. The chastooshka is a folklore element.

«United States» - Rivers and lakes. United States border with Canada, Mexico, and Russia. Population - more than 309 million people (third place). In the south of the U.S. border with Mexico, to the north - Canada. There is a vice-president. Stoke on the St. population. USA. Here are found several species of alligators and poisonous snakes.

Без темы

661 презентация
Урок

Английский язык

29 тем
Картинки