Link to home
Start Free TrialLog in
Avatar of prashanth_gurijala
prashanth_gurijala

asked on

Interface to display the values which are sent by server program

Actually, here are my client and server codes. Can any one integrate code to my client.So, that after connecting to the server the 8 values which it gets from server are displayed in text boxes(now they are displayed on command prompt) and also my server sends 8 values .can you add code that these values are refreshed for every 5 seconds and displayed in the interface on client side.. and labels of  8 values are as follows...
Sky Condition: Temperature: Humidity: Wind Speed: Barometer:      Dewpoint:Heat Index: Visibility:


--------------
import java.net.*;
import java.io.*;

public class Server
{
     public Server()
     {
          try
          {
               //creating server socket binding at port # 3000
               ServerSocket server=new ServerSocket(3000);
               System.out.println("Server binded at "+((server.getInetAddress()).getLocalHost()).getHostAddress()+":3000");
               System.out.println("Run the Client");
               //ready to accept client request
               Socket socket=server.accept();
               //opening the input stream to read data from client connection
               BufferedReader in= new BufferedReader(new InputStreamReader(socket.getInputStream()));
               System.out.println(in.readLine());
               //using output stream responsing data
               DataOutputStream out=new DataOutputStream(socket.getOutputStream());
               for (int i=0; i<8; i++)
               {
                      int s =(int)(Math.random()*10);
                       out.writeInt(s*10);
               }
               out.flush();
               //closing the in & out streams
               out.close();
               in.close();
          }
          catch(Exception err)
          {
               System.err.println("* err"+err);
          }
               
     }
     
     public static void main(String a[])
     {
          new Server();
     }
     
}

client code
------------------------------------
import java.net.*;
import java.io.*;

public class Client
{
     
     public Client()
     {
          try
          {
               //ceating the socket to connect to server running on same machine binded on port no 3000
               Socket client=new Socket("localhost",3000);
               System.out.println("Client connected ");
               //getting the o/p stream of that connection
               PrintStream out=new PrintStream(client.getOutputStream());
               //sending the message to server
               out.print("Hello from client\n");
               out.flush();
               //reading the response using input stream
               DataInputStream in= new DataInputStream(client.getInputStream());
               for (int i=0; i<8; i++)
               {
                  System.out.println(in.readInt());
               }
               //closing the streams
               in.close();
               out.close();
 
          }
          catch(Exception err)
          {
               System.err.println("* err"+err);
          }
               
     }
     
     public static void main(String a[])
     {
          new Client();
     }
     
}
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial