Results 1 to 5 of 5
Thread: Help what is the error
- 09-22-2009, 12:28 PM #1
Member
- Join Date
- Sep 2009
- Posts
- 2
- Rep Power
- 0
Help what is the error
Hi friends,
I begin to learn java about a month ago. I just got a client server chat program.It compiles well and makes the server and client classes. But when running the server message is passed to the client . The vice versa is not happening. I dont know any details of socket programming. So please explain the program for me. Please. Thx in advance
SERVER
import java.net.*;
import java.io.*;
public class Server extends Thread
{
public static ServerSocket sc;
public String str;
public BufferedReader r1,r2;
public PrintStream w;
public Server(Socket s)
{
try
{
r1=new BufferedReader(new InputStreamReader(s.getInputStream()));
r2=new BufferedReader(new InputStreamReader(System.in));
w=new PrintStream(s.getOutputStream());
this.start();
for(;;)
{
str=r2.readLine();
w.println("server:"+str);
}
}
catch(Exception e)
{
System.out.println(e);
}
}
public static void main(String args[])
{
try
{
sc=new ServerSocket(4520);
new Server (sc.accept());
}
catch(Exception e)
{
System.out.println(e);
}}}
CLIENT
import java.net.*;
import java.io.*;
public class Client extends Thread
{
public Socket s;
public String str;
public BufferedReader r1,r2;
PrintStream w;
public Client()
{
try
{
InetAddress address=InetAddress.getLocalHost();
s=new Socket(address,4520);
r1=new BufferedReader(new InputStreamReader(s.getInputStream()));
}
catch(Exception e)
{
System.out.println(e);
}
}
public void run()
{
try
{
for(;;)
System.out.println(this.r1.readLine());
}
catch(Exception e)
{
System.out.println(e);
}
}
public static void main(String args[])
{
try
{
String ad=String.valueOf(InetAddress.getLocalHost())+":";
Client A=new Client();
A.r2=new BufferedReader(new InputStreamReader(System.in));
A.w=new PrintStream(A.s.getOutputStream());
A.start();
for(;;)
{
String s=A.r2.readLine();
A.w.println(ad+s);
}
}
catch(Exception e)
{
System.out.println(e);
}
}
}
- 09-22-2009, 12:31 PM #2
Member
- Join Date
- Sep 2009
- Posts
- 2
- Rep Power
- 0
One minute. The Smiley there isnt by me.(;)
- 09-22-2009, 01:02 PM #3
Senior Member
- Join Date
- Aug 2009
- Posts
- 2,388
- Rep Power
- 6
- 09-22-2009, 05:07 PM #4
the problem is the smiley!
- 09-22-2009, 06:01 PM #5
Moderator
- Join Date
- Apr 2009
- Posts
- 10,481
- Rep Power
- 16
Similar Threads
-
Diference Between compiler error Garbage collection and Runtime Error?
By makpandian in forum New To JavaReplies: 3Last Post: 01-23-2009, 08:53 AM -
error 530 error authentication required
By rgale in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 05-12-2008, 04:28 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks