













Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
This lecture was delivered by Prof. Mudita Tiwari at Cochin University of Science and Technology for Java Programming course. It includes: Networking, Socket, Programming, Communication, Link, Hosts, Ports, Dynamics, Sending, Receiving
Typology: Lecture notes
1 / 21
This page cannot be seen from the preview
Don't miss anything!














Socket programming
A socket is a endpoint of a two-way communication link between two programmes running on the network
Socket is a bidirectional communication channel between hosts( a computer on a network can be termed as a host)
Communication link
Socket (endpoints)
A socket is an abstraction of the network similar to the way a file is an abstraction of system’s hard drive. We store and retrieve data through files from hard drive without knowing the actual dynamics of the hard drive. Similarly we send and receive data to and from network through socket without actually going into underlying mechanics.
We read from or write data to a file using streams. Similarly to read from or write data to a socket, we use streams
Transport address to which processes can listen for connection requests Computer can listen on that specific transport address where some request is being sent. Local to host: 64k TCP and 64k UDP ports Well known ports Below 1024 Standard services
Import required packages Connect/open a socket with server Get I/O streams of socket Send/ Receive message Close socket
Send/ Receive message pw.println(“hello”); String recieveMsg=br.readLine(); Close socket S.close(); Br.close(); Pw.close();
Import required packages Create a Server socket Wait for incoming connection Get I/O streams of communication socket Send/ Receive message Close socket
Get I/O streams of socket
InputStream is=s.getInputStream() InputStreamReader isr=new InputStreamR(is); BufferedReader br=new BufferedReader(isr); OutputStream os=s.getOutputStream() PrintWriter pw=new PrintWriter(os,true)
Send/ Receive message pw.println(“hello”); String recieveMsg=br.readLine(); Close socket S.close(); Br.close(); Pw.close();