Skip to content

Commit de721ca

Browse files
committedSep 15, 2013
Create QueryClient
This program takes a student's number as an argument. This program will send the student's number as a request to the server and wait for the server's reply. This program will display the student's contact details once it receives from the server. This program uses UDP as the communication protocol to program the client and the server interaction.
1 parent 12bf3ff commit de721ca

File tree

1 file changed

+40
-0
lines changed

1 file changed

+40
-0
lines changed
 

‎QueryClient

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* To change this template, choose Tools | Templates
3+
* and open the template in the editor.
4+
*/
5+
6+
7+
import java.net.*;
8+
import java.io.*;
9+
import java.util.Scanner;
10+
/**
11+
*
12+
* @author Reza Nourbakhsh
13+
*/
14+
public class QueryClient {
15+
16+
17+
public static void main(String args[]) throws Exception
18+
{
19+
20+
BufferedReader inFromUser =
21+
new BufferedReader(new InputStreamReader(System.in));
22+
DatagramSocket clientSocket = new DatagramSocket();
23+
InetAddress IPAddress = InetAddress.getByName("localhost");
24+
System.out.println("Enter Student ID:");
25+
byte[] sendData = new byte[1024];
26+
byte[] receiveData = new byte[1024];
27+
String sentence = inFromUser.readLine();
28+
sendData = sentence.getBytes();
29+
DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.length, IPAddress, 9875);
30+
clientSocket.send(sendPacket);
31+
DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.length);
32+
clientSocket.receive(receivePacket);
33+
String modifiedSentence = new String(receivePacket.getData());
34+
System.out.println("FROM SERVER:" + modifiedSentence);
35+
clientSocket.close();
36+
}
37+
38+
39+
40+
}

0 commit comments

Comments
 (0)
Please sign in to comment.