Aim To implement a chat server and client in java using UDP sockets. Algorithm
Server 1. Create two ports, server port and client port 2. Create a datagram socket and bind it to client port 3. Create a datagram packet to receive client message 4. Wait for client's data and accept it. 5. Read Client's message 6. Get data from user 7. Construct a datagram packet and send message through server port 8. Repeat steps 3-7 until the client has something to send 9. Close the server socket 10. Stop Client 1. 2. 3. 4. 5. 6. 7. 8. 9.
Create two ports, server port and client port Create a datagram socket and bind it to server port Get data from user Create a datagram packet and send data with server ip address and client port Create a datagram packet to receive server message Read server's response and display it Repeat steps 3-6 until there is some text to send Close the client socket Stop
Result Thus both the client and server exchange data using UDP sockets.
http://cseannauniv.blogspot.com
Vijai Anand
CS2307 – Network Lab
Socket Programming
Program // UDP Chat Server--udpchatserver.java import java.io.*; import java.net.*; class udpchatserver { public static int clientport = 8040,serverport = 8050; public static void main(String args[]) throws Exception { DatagramSocket SrvSoc = new DatagramSocket(clientport); byte[] SData = new byte[1024]; BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); System.out.println("Server Ready"); while (true) { byte[] RData = new byte[1024]; DatagramPacket RPack = new DatagramPacket(RData, RData.length); SrvSoc.receive(RPack); String Text = new String(RPack.getData()); if (Text.trim().length() == 0) break; System.out.println("\nFrom Client <<< " + Text ); System.out.print("Msg to Cleint : " ); String srvmsg = br.readLine(); InetAddress IPAddr = RPack.getAddress(); SData = srvmsg.getBytes(); DatagramPacket SPack = new DatagramPacket(SData, SData.length, IPAddr, serverport); SrvSoc.send(SPack); } System.out.println("\nClient Quits\n"); SrvSoc.close(); } }
http://cseannauniv.blogspot.com
Vijai Anand
CS2307 – Network Lab
Socket Programming
// UDP Chat Client--udpchatclient.java import java.io.*; import java.net.*; class udpchatclient { public static int clientport = 8040,serverport = 8050; public static void main(String args[]) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader (System.in)); DatagramSocket CliSoc = new DatagramSocket(serverport); InetAddress IPAddr; String Text; if (args.length == 0) IPAddr = InetAddress.getLocalHost(); else IPAddr = InetAddress.getByName(args[0]); byte[] SData = new byte[1024]; System.out.println("Press Enter without text to quit"); while (true) { System.out.print("\nEnter text for server : "); Text = br.readLine(); SData = Text.getBytes(); DatagramPacket SPack = new DatagramPacket(SData, SData.length, IPAddr, clientport ); CliSoc.send(SPack); if (Text.trim().length() == 0) break; byte[] RData = new byte[1024]; DatagramPacket RPack = new DatagramPacket(RData, RData.length); CliSoc.receive(RPack); String Echo = new String(RPack.getData()) ; Echo = Echo.trim(); System.out.println("From Server <<< " + Echo); } CliSoc.close(); } }
http://cseannauniv.blogspot.com
Vijai Anand
CS2307 – Network Lab
Socket Programming
Output
Server Console $ javac udpchatserver.java $ java udpchatserver Server Ready From Client <<< are u the SERVER Msg to Cleint : yes From Client <<< what do u have to serve Msg to Cleint : no eatables Client Quits
Client Console $ javac udpchatclient.java $ java udpchatclient Press Enter without text to quit Enter text for server : are u the SERVER From Server <<< yes Enter text for server : what do u have to serve From Server <<< no eatables Enter text for server :
6. Stop. Client. 1. Create a socket. 2. Send physical address to the target machine. 3. Receive target's response. 4. If it is a IP address then display it and go to step 6 ... Program. //RARP Server -- rarpserver.java import java.io.*; import java.n
Security Model, Components of an Information System, Securing the ... Information security is to protect the confidentiality, integrity and availability of information ...
Relevent Coursework Algorithm Analysis and Design, Operating Systems, Microprocessors, Real-time and Embedded Systems,. Data Structures, Signals and ...
TCP guarantees the delivery of packets and preserves their order on destination. Sometimes these features are not required, since they do not come without performance costs, it would be better to use a lighter transport protocol such as UDP (User Dat
students about various aspects of power, culture, poverty, society, media and social change,. including globalization. His current research work includes political ...
Sign in. Loading⦠Whoops! There was a problem loading more pages. Retrying... Whoops! There was a problem previewing this document. Retrying.Missing:
Sign in. Loading⦠Whoops! There was a problem loading more pages. Whoops! There was a problem previewing this document. Retrying... Download. Connect ...
To exchange message between server and client using message queue. Algorithm. Server. 1. Decalre a structure mesgq with type and text fields. 2. Initialize key to 2013 (some random value). 3. Create a message queue using msgget with key & IPC_CREAT a
Spatial Filters. ⢠Implement and analyse the following Spatial filters. ... Note: Do not use of built in matlab functions for filter implementation. 1. Page 1. Exp III.pdf.
M.Eng. IISc Bangalore born on 26. May 1976, in India the title ... The Chairman of the Department of. Information Technology and Electrical Engineering. Prof.
Whoops! There was a problem loading more pages. Retrying... teaching-exp-certificate.pdf. teaching-exp-certificate.pdf. Open. Extract. Open with. Sign In.Missing:
There was a problem previewing this document. Retrying... Download. Connect more apps... Try one of the apps below to open or edit this item. exp-monitoramento - Web.pdf. exp-monitoramento - Web.pdf. Open. Extract. Open with. Sign In. Main menu.
It has a big knob on top that allows you to dial in whatever output voltage you want. Working of transformer: The principle of the transformer is illustrated by ...
Connect terminal S6 to terminal Re1 and terminal Re2 to terminal R1. 6. .... I6. I0ut. Deptt. Of electrical engineering, SOE, GBU, Greater Noida (U.P.) 201308 ..... 10. Switch off the mains supply. Observation Table: Transformer. Vp. Vs. K ...
There was a problem previewing this document. Retrying... Download. Connect more apps... Try one of the apps below to open or edit this item. 2b 2 w4wn ...
11. The Ministerial Conference of the world Trade. Organization was held at Cancun, Cancun is located in ____. (1) Uruguay (2) Venezuela (3) Mexico. (4) Honduras (5) Bahrain. Page 3 of 14. Main menu. Displaying (www.entrance-exam.net)-Institute of Ru
What would you keep in a treasure chest? â Do you like to spend or save money? Why? â What is something you love to do with your mother? Page 1 of 3 ...
Page 1. Whoops! There was a problem loading more pages. untouchable mulk raj anand pdf. untouchable mulk raj anand pdf. Open. Extract. Open with. Sign In.
There was a problem previewing this document. Retrying... Download. Connect more apps... Try one of the apps below to open or edit this item. Exp 4.pdf. Exp 4.
Loading⦠Whoops! There was a problem loading more pages. Whoops! There was a problem previewing this document. Retrying... Download. Connect more apps... Try one of the apps below to open or edit this item. ciencia exp 2014_esa.pdf. ciencia exp 201