1 Attachment(s)
Really big problem in client and server program
Friends here is my client program in java using sockets
Code:
import java.io.*;
import java.net.*;
class Client
{
int count=0;
public static void main(String args[]) throws Exception
{
int count=0;
Socket s=new Socket("LocalHost",2000);
DataOutputStream dos=new DataOutputStream(s.getOutputStream());
String str=new String();
while(true)
{
try
{
Thread.sleep(1000);
count++;
str=""+count+"";
dos.writeBytes("str");
System.out.println(str);
}
catch(Exception e)
{}
}
}
}
Here client sends seconds to server by using thread and incrementing a variable for every 1 second.
And server program is
Code:
import java.io.*;
import java.net.*;
class Server
{
public static void main(String args[]) throws Exception
{
ServerSocket ss=new ServerSocket(2000);
Socket s=ss.accept();
DataInputStream dis=new DataInputStream(s.getInputStream());
String str=dis.readLine();
System.out.println("While");
while(true)
{
System.out.println(str);
str=dis.readLine();
}
}
}
THERE IS NO ERRORS IN ABOVE CODE
Now the big problem is server is waiting for message from client , but client is posting the values to the server program.
When i execute the program by executing server first next to client(which is to be) client is sending data (which i can see the values the client is printing in cmd) but server program just stays in the line "String str=dis.readLine();" and just waiting for input...
So please help me in getting this code..
Thanks.....