Socket programming
Socket programming
goal: learn how to build client/server applications that communicate using sockets
socket: dropbox between application process and endend-transport protocol
application
process
transport network
link physical
socket
Internet
application
process
transport network
link physical
controlled by app developer
controlled by OS
Application Layer 2-1
Socket programming
Two socket types for two transport services: ? UDP: unreliable datagram ? TCP: reliable, byte stream-oriented
Application Example: 1. Client reads a line of characters (data) from its
keyboard and sends the data to the server. 2. The server receives the data and converts
characters to uppercase. 3. The server sends the modified data to the client. 4. The client receives the modified data and displays
the line on its screen.
Application Layer 2-2
Socket programming with UDP
UDP: no "connection" between client & server
v no handshaking before sending data v sender explicitly attaches IP destination address and
port # to each packet v rcvr extracts sender IP address and port# from
received packet
UDP: transmitted data may be lost or received out-of-order
Application viewpoint:
vUDP provides unreliable transfer of groups of bytes ("datagrams") between client and server
Application Layer 2-3
Client/server socket interaction: UDP
server (running on serverIP)
create socket, port= x: serverSocket = DatagramSocket(x)
read datagram from serverSocket
write reply to serverSocket specifying client address, port number
client
create socket: clientSocket = DatagramSocket()
Create datagram with server IP and port=x; send datagram via clientSocket
read datagram from clientSocket
close clientSocket
Application 2-4
Example: Java client (UDP)
import java.io.*; import .*;
create input stream
create client socket
translate hostname to IP addr using DNS
class UDPClient { public static void main(String args[]) throws Exception {
BufferedReader inFromUser = new BufferedReader(new InputStreamReader(System.in));
DatagramSocket clientSocket = new DatagramSocket();
InetAddress IPAddress = InetAddress.getByName("hostname");
byte[] sendData = new byte[1024]; byte[] receiveData = new byte[1024];
String sentence = inFromUser.readLine(); sendData = sentence.getBytes();
Application Layer 2-5
................
................
In order to avoid copyright disputes, this page is only a partial summary.
To fulfill the demand for quickly locating and searching documents.
It is intelligent file search solution for home and business.
Related download
- application layer and socket programming
- functions open michigan
- 1 functions in python
- cse 231 fall 2009 programming project 1
- programming by example
- problem set 1 mit opencourseware
- python beginner tutorials
- chapter 1 scalar variables and data types
- python programming basics
- cs348 computer networks socket programming
Related searches
- infected tooth socket pictures
- infected socket after tooth extraction
- how to prevent dry socket after extraction
- will dry socket heal without treatment
- harbor freight 3 4 socket set
- c tcp socket server
- dry socket prevention tips
- 9 32 socket to mm
- pictures of tooth socket healing
- tooth socket infection
- wisdom tooth dry socket pictures
- dry socket after tooth extraction