sockets
Download
Skip this Video
Download Presentation
Sockets

Loading in 2 Seconds...

play fullscreen
1 / 24

Sockets - PowerPoint PPT Presentation


  • 106 Views
  • Uploaded on

Sockets. contents. 0x421 Socket Functions 0x422 Socket Addresses 0x423 Network Byte Order 0x424 Internet Address Conversion 0x425 A Simple Server Example 0x426 A Web Client Example 0x427 A Tinyweb Server. 0x420 Sockets.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' Sockets' - fauve


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
contents
contents
  • 0x421 Socket Functions
  • 0x422 Socket Addresses
  • 0x423 Network Byte Order
  • 0x424 Internet Address Conversion
  • 0x425 A Simple Server Example
  • 0x426 A Web Client Example
  • 0x427 A TinywebServer
0x420 sockets
0x420 Sockets
  • A socket is a standard way to perform network communication through the OS.
  • There are two kinds of sockets.
    • Stream socket
      • Provide reliable two-way communication similar to when you call someone on the phone
    • Datagram socket
      • Communicating with a datagram socket is more like mailing a letter than making a phone call. The connection is one-way only and unreliable.
0x421 socket functions
0x421 Socket Functions
  • socket(int domain, int type, int protocol)
    • Used to create a new socket, returns a file descriptor for the socket or -1 on error.
  • connect(intfd, structsockaddr *remote_host, socklen_taddr_length)
    • Connects a socket to a remote host. Returns 0 on success and -1 on error.
  • bind(intfd, structsockaddr *local_addr, socklen_taddr_length)
    • Binds a socket to a local address so it can listen for incoming connections. Returns 0 on success and -1 on error.
  • listen(intfd, intbacklog_queue_size)
    • Listens for incoming connections and queues connection requests up to backlog_queue_size. Returns 0 on success and -1 on error.
0x421 socket functions1
0x421 Socket Functions
  • accept(intfd, sockaddr *remote_host, socklen_t *addr_length)
    • Accepts an incoming connection on a bound socket. The address information from the remote host is written into the remote_host structure and the actual size of the address structure is written into *addr_length. This function returns a new socket file descriptor to identify the connected socket or -1 on error.
  • send(intfd, void *buffer, size_t n, int flags)
    • Sends n bytes from *buffer to socket fd; returns the number of bytes sent or -1 on error.
  • recv(intfd, void *buffer, size_t n, int flags)
    • Receives n bytes from socket fd into *buffer; returns the number of bytes received or -1 on error.
0x421 socket functions2
0x421 Socket Functions
  • Socket.h

We usually use this prtocol

If you have played starcraft, you know this protocol

0x421 socket functions3
0x421 Socket Functions
  • Socket.h

almost always be 0

0x422 socket addresses
0x422 Socket Addresses
  • If you dedicate a Protocol family, Address family will automatically determined
0x422 socket addresses1
0x422 Socket Addresses
  • sa = Socket Address
0x423 network byte order
0x423 Network Byte Order
  • The port number and IP address used in the AF_INET socket address structure are expected to follow the network byte ordering, which is big-endian. This is the opposite of x86’s little-endian byte ordering, so these values must be converted.
0x425 a simple server example2
0x425 A Simple Server Example

Sockfd – Socket file descriptor

SOL_SOCKET - There are many different socket options defined in /usr/include/asm/socket.h

SO_REUSEADDR - SOL_SOCKET 일 경우 옵션의 하나

- 이미 사용하고 있는 어드레스를 바인드 할 수 있도록 한다.

0x427 a tinyweb server
0x427 A Tinyweb Server
  • Tinyweb.c
    • 127.0.0.1
0x427 a tinyweb server1
0x427 A Tinyweb Server
  • Tinyweb.c
    • 127.0.0.1
ad