This is a simple server/client program. What i'm trying to do is let the server send a message to the client, the client should receive this message and print this message on screen. When i run the program the server prints "Server start" like its supposed to but nothing happens on the client part ...Pls Help!
import java.net.*;
import java.io.*;
public class server1
{
public static void main(String args[]) throws Exception
{
try {
DatagramSocket serverSocket = new DatagramSocket();
InetAddress address = InetAddress.getByName("localhost");
byte sendData[]=new byte[2048];
byte receiveData[]=new byte[2048];
System.out.println("Server Start");
String Welcome = "You are now connected to server on this port ";
sendData = Welcome.getBytes();
DatagramPacket packet = new DatagramPacket(sendData,sendData.length,address,7777);
serverSocket.send(packet);
serverSocket.close();
}catch (Exception e) {
System.err.println(e);
}//end of catch
}//end of main
}//end of class
import java.net.*;
import java.io.*;
public class client1
{
public static void main(String args[]) throws Exception
{
try {
DatagramSocket clientSocket = new DatagramSocket(7777);
InetAddress address = InetAddress.getByName("localhost");
byte[] sendData = new byte[2048];
byte[] receiveData = new byte[2048];
DatagramPacket packet = new DatagramPacket(receiveData,receiveData.length);
while(true)
{
clientSocket.receive(packet);
String sentence=new String(packet.getData());
System.out.println("Server says: "+sentence+" ");
clientSocket.close();
}//end of while
}catch (Exception e){
System.err.println(e);
}//end of catch
} //end of main
}//end of client