socket programming
Download
Skip this Video
Download Presentation
Socket Programming

Loading in 2 Seconds...

play fullscreen
1 / 18

Socket Programming - PowerPoint PPT Presentation


  • 84 Views
  • Uploaded on

Socket Programming. With TCP and UDP. Christoffer Brodd-Reijer Zaruhi Aslanyan. Socket. High level connection between two hosts Identified by port+IP Transport layer (UDP, TCP, etc) or raw IP. Socket. Similar to operating on a file: open read/write close. Socket.

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 'Socket Programming' - juro


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
socket programming

Socket Programming

With TCP and UDP

  • ChristofferBrodd-Reijer
  • ZaruhiAslanyan
socket
Socket
  • High level connection between two hosts
  • Identified by port+IP
  • Transport layer (UDP, TCP, etc) or raw IP
socket1
Socket

Similar to operating on a file:

  • open
  • read/write
  • close
socket2
Socket

Systematic overview:

slide5
TCP
  • Transmission Control Protocol
  • Created in 1974
  • Operates on of a stream of octets (bytes)
slide6
TCP

Proc

  • Connection orientated
  • Reliable
  • Ordered

Cons

  • Slow
  • Complex

Good for

  • World Wide Web
  • Remote administration
  • File transfer (FTP)
  • Electronic mail (SMTP)
slide7
TCP

Using TCP sockets in C on UNIX:

// create socket

s = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)

// receive data

recvfrom(s, buf, len, flags, &scr_addr, &addrlen)

// send data

sendto(s, buf, len, flags, &dect_addr, addrlen)

slide8
TCP

Using TCP sockets in Java:

// create socket

Socket s = new Socket(address, port);

// receive data

InputStream in = s.getInputStream();

// send data

OutputStream out = s.getOutputStream();

slide9
TCP

Using TCP sockets in Ruby:

// create socket

s = TCPSocket.new(host, port)

// receive data

str = s.recv(len[, flags])

// send data

s.send(mesg, flags[, to])

slide10
TCP

Using TCP sockets in Python:

// create socket

s = socket.socket([socket.AF_INET[,socket.SOCK_STREAM]])

// receive data

socket.recv(bufsize[, flags])

// send data

socket.sendall(string[, flags])

slide11
UDP
  • User Datagram Protocol
  • Created in 1980
  • Operates on whole datagrams (messages); not bytes
slide12
UDP

Cons:

  • Unreliable delivery
  • Unreliable order
  • Possible duplication

Pros:

  • Simple
  • Fast

Good for:

  • Streaming
  • Gaming
  • Name lookup (DNS)
  • Time lookup (NTP)
slide13
UDP

Using UDP sockets in C on UNIX:

// create socket

s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)

// receive data

recvfrom(s, buf, LEN, 0, &opt, &optlen)

// send data

sendto(s, buf, LEN, 0, &opt, optlen)

slide14
UDP

Using UDP sockets in Java:

// create socket

s = new DatagramSocket(PORT);

// receive data

p = new DatagramPacket(buf, buf.length);

s.receive(p);

// send data

p = new DatagramPacket(buf, buf.length, IP, PORT)

s.send(p);

slide15
UDP

Using UDP sockets in Ruby:

// create socket

s = UDPSocket.new

// receive data

msg, sender = s.recv_from MAXLEN

// send data

s.send msg, OPTIONS

slide16
UDP

Using UDP sockets in Python:

// create socket

s = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)

// receive data

msg = s.recv(MAXLEN)

// send data

s.sendall(msg)

summary
Summary
  • Socket: End-to-End handler
  • TCP: connection, bytes, reliable
  • UDP: datagrams, fast, simple
  • Code is similar between languages (same principles applies)
ad