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( )).getLoca lHost()).g etHostAddr ess()+":30 00");
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.g etInputStr eam()));
System.out.println(in.read Line());
//using output stream responsing data
DataOutputStream out=new DataOutputStream(socket.ge tOutputStr eam());
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.getOutp utStream() );
//sending the message to server
out.print("Hello from client\n");
out.flush();
//reading the response using input stream
DataInputStream in= new DataInputStream(client.get InputStrea m());
for (int i=0; i<8; i++)
{
System.out.println(in.read Int());
}
//closing the streams
in.close();
out.close();
}
catch(Exception err)
{
System.err.println("* err"+err);
}
}
public static void main(String a[])
{
new Client();
}
}
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
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.g
System.out.println(in.read
//using output stream responsing data
DataOutputStream out=new DataOutputStream(socket.ge
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
//getting the o/p stream of that connection
PrintStream out=new PrintStream(client.getOutp
//sending the message to server
out.print("Hello from client\n");
out.flush();
//reading the response using input stream
DataInputStream in= new DataInputStream(client.get
for (int i=0; i<8; i++)
{
System.out.println(in.read
}
//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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.