Port is a transport address to which processes can ________ for connections request.
- Aread
- BWrite
- CListen
- DNone of the given options
A server process listens on a port for connection requests.
MCQs, short and long questions from lecture 21.Lecture 21 ki MCQs, short aur long sawal.
3 MCQs · 2 short · 2 long questions · 3 MCQs from past papers3 MCQs · 2 short · 2 long sawal · 3 MCQs past papers se
Port is a transport address to which processes can ________ for connections request.
A server process listens on a port for connection requests.
What is not true about server socket:
A ServerSocket only listens; communication is done by the normal Socket returned by accept().
Stream is an abstraction of hard drive same as socket is an abstraction of __________.
A socket is the software abstraction of a network connection.
No MCQs match this filter.Is filter mein koi MCQ nahi.
What is socket?
A socket is one endpoint of a two-way communication link between two programs running on a network. It is identified by an IP address and a port number.
What is the difference between client socket and server socket?
A client socket (java.net.Socket) is created on the client and connects to a given server host and port; it is then used for communication (reading and writing streams). A server socket (java.net.ServerSocket) runs on the server, binds to a port and only listens for incoming connection requests; when accept() receives a request it returns a new ordinary Socket that is used to communicate with that client. The server socket itself is not used for data communication.
What is difference between socket and server socket? Also right java syntax to create socket and server socket. Write solution by filling given table. (Table with columns: Socket | Server Socket)
Socket: the client-side endpoint of a connection; it connects to a server at a given host and port and is used to send and receive data through its input and output streams. Syntax: Socket s = new Socket("localhost", 2222); ServerSocket: used on the server side; it listens on a port and waits for client requests; accept() blocks until a client connects and then returns a Socket for talking to that client. Syntax: ServerSocket ss = new ServerSocket(2222); Socket s = ss.accept();
Create a server program that receives user's NIC number from client and sends it back to the client whose IP address is: 196.192.1.2 residing on the port 1008. server resides on the 1299 port. The message should be sent in the following format: "Your [user given NIC number] shall be safe". You are not supposed to write a client program.
import java.net.*; import java.io.*; public class NicServer { public static void main(String[] args) { try { ServerSocket ss = new ServerSocket(1299); // server listens on port 1299 Socket s = ss.accept(); // wait for the client (196.192.1.2) BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream())); PrintWriter pw = new PrintWriter(s.getOutputStream(), true); String nic = br.readLine(); // NIC number from client pw.println("Your " + nic + " shall be safe"); // send it back br.close(); pw.close(); s.close(); ss.close(); } catch (IOException e) { System.out.println(e); } } } The reply goes back over the connected socket, which already links to the client at 196.192.1.2 (port 1008), so no new connection is needed.