TCP??????? - PowerPoint PPT Presentation

About This Presentation
Title:

TCP???????

Description:

Title: Author: Last modified by: Created Date: 6/8/2004 8:59:07 AM Document presentation format – PowerPoint PPT presentation

Number of Views:21
Avg rating:3.0/5.0
Slides: 8
Provided by: 21079
Category:
Tags: tcp

less

Transcript and Presenter's Notes

Title: TCP???????


1
TCP???????
  • ????
  • http//okaweb.ec.kyushu-u.ac.jp/lectures/in-ng/

2
TCP???????(????)
include ltstdio.hgt include ltstrings.hgt include
ltsys/types.hgt include ltsys/socket.hgt include
ltnetinet/in.hgt main(narg,arg) int narg
char arg int sock,sock2,saddr2_len int
s_addr unsigned short port struct
sockaddr_in saddr,saddr2 s_addrinet_addr(arg
1) portatoi(arg2) bzero(saddr,sizeof(s
truct sockaddr_in)) bzero(saddr2,sizeof(struct
sockaddr_in)) saddr.sin_family
AF_INET saddr.sin_addr.s_addr s_addr
saddr.sin_port htons(port)
socksocket(AF_INET, SOCK_STREAM, IPPROTO_TCP)
switch (arg30) case 'b'
if(bind(sock, (struct sockaddr )saddr,sizeof(sad
dr)) lt 0) perror("TCPbind ")
return -1 listen(sock,8)
sock2accept(sock,(struct sockaddr
)saddr2,saddr2_len) printf("connected
from s.\n",inet_ntoa(saddr2.sin_addr))
break case 'c' if(connect(sock, (struct
sockaddr )saddr,sizeof(saddr)) lt 0)
perror("TCPconnect ") return -1
getchar() break close (sock)
3
TCP ? UDP ???(bind)
  • UDP
  • bind ??????ID?????????
  • TCP
  • bind ???????ID ? accept ??????????????????accept
    ??????????ID???????? ID ????????????

4
bind ??????IP????
saddr.sin_family AF_INET saddr.sin_addr.s_
addr s_addr saddr.sin_port
htons(port) socksocket(AF_INET, SOCK_STREAM,
IPPROTO_TCP) if(bind(sock, (struct sockaddr
)saddr,sizeof(saddr)) lt 0)
perror("TCPbind ")
?????????????????? ???????????????????????????????
???????? 0.0.0.0 ?????????????????????????????????
????????
5
TCP ? UDP ???(connect)
  • UDP
  • ????? bind ??????? connect ??????
  • TCP
  • connect ????????????????? bind/listen/accept
    ??????????

6
????????????
  • TCP ? UDP ???? write() ??????????????????????read(
    )???????????????????????
  • ????TCP ? bind ??????ID?????accept ??????ID?

7
??
  • UDP ???????? EOF ?????????????? TCP ???????????
  • ????????????????????
  • ?Mbyte??????????????????????
Write a Comment
User Comments (0)
About PowerShow.com