|
-
March 6th, 2010, 06:28 AM
#1
chatting Project
import java.io.*;
import java.net.*;
import java.util.*;
public class MyServer{
ServerSocket ss;
Socket s;
ArrayList al=new ArrayList();
ArrayList al1=new ArrayList();
ArrayList al2=new ArrayList();
ArrayList alname=new ArrayList();
Socket s1,s2;
MyServer()throws IOException{
ss=new ServerSocket(1004); // create server socket
while(true){
s=ss.accept(); //accept the client socket
s1=ss.accept();
s2=ss.accept();
al.add(s); // add the client socket in arraylist
al1.add(s1);
al2.add(s2);
System.out.println("Client is Connected");
MyThread2 m=new MyThread2(s2,al2,alname); //new thread for maintaning the list of user name
Thread t2=new Thread(m);
t2.start();
MyThread r=new MyThread(s,al);//new thread for receive and sending the messages
Thread t=new Thread(r);
t.start();
MyThread1 my=new MyThread1(s1,al1,s,s2); // new thread for update the list of user name
Thread t1=new Thread(my);
t1.start();
}
}
public static void main(String[] args){
try{
new MyServer();
}catch (IOException e){}
}
}
//class is used to update the list of user name
class MyThread1 implements Runnable{
Socket s1,s,s2;
static ArrayList al1;
DataInputStream ddin;
String sname;
MyThread1(Socket s1,ArrayList al1,Socket s,Socket s2){
this.s1=s1;
this.al1=al1;
this.s=s;
this.s2=s2;
}
public void run(){
try{
ddin=new DataInputStream(s1.getInputStream());
while(true){
sname=ddin.readUTF();
System.out.println("Exit :"+sname);
MyThread2.alname.remove(sname);//remove the logout user name from arraylist
MyThread2.every();
al1.remove(s1);
MyThread.al.remove(s);
MyThread2.al2.remove(s2);
if(al1.isEmpty())
System.exit(0); //all client has been logout
}
}catch(Exception ie){}
}
}
// class is used to maintain the list of all online users
class MyThread2 implements Runnable{
Socket s2;
static ArrayList al2;
static ArrayList alname;
static DataInputStream din1;
static DataOutputStream dout1;
MyThread2(Socket s2,ArrayList al2,ArrayList alname){
this.s2=s2;
this.al2=al2;
this.alname=alname;
}
public void run(){
try{
din1= new DataInputStream(s2.getInputStream());
alname.add(din1.readUTF()); // store the user name in arraylist
every();
}catch(Exception oe){System.out.println("Main expression"+oe);}
}
// send the list of user name to all client
static void every()throws Exception{
Iterator i1=al2.iterator();
Socket st1;
while(i1.hasNext()){
st1=(Socket)i1.next();
dout1=new DataOutputStream(st1.getOutputStream());
ObjectOutputStream obj=new ObjectOutputStream(dout1);
obj.writeObject(alname); //write the list of users in stream of all clients
dout1.flush();
obj.flush();
}
}
}
//class is used to receive the message and send it to all clients
class MyThread implements Runnable{
Socket s;
static ArrayList al;
DataInputStream din;
DataOutputStream dout;
MyThread(Socket s, ArrayList al){
this.s=s;
this.al=al;
}
public void run(){
String str;
int i=1;
try{
din=new DataInputStream(s.getInputStream());
}catch(Exception e){}
while(i==1){
try{
str=din.readUTF(); //read the message
distribute(str);
}catch (IOException e){}
}
}
// send it to all clients
public void distribute(String str)throws IOException{
Iterator i=al.iterator();
Socket st;
while(i.hasNext()){
st=(Socket)i.next();
dout=new DataOutputStream(st.getOutputStream());
dout.writeUTF(str);
dout.flush();
}
}
}
I do't know what it means..
need serious help.
-
March 6th, 2010, 08:14 AM
#2
Re: chatting Project
I do't know what it means..
I guess that means it's not your code so where did you get it from, why do you have it, what are you wanting to do with it and what's your question?
-
March 6th, 2010, 10:49 AM
#3
Re: chatting Project
yeah! you r right.
today i was told by my head sir to submit project on java wed development.
and i have only one day to understand it and demonstrate it.
so i have taken it from someone.
need urgent help!!
-
March 6th, 2010, 10:51 AM
#4
Re: chatting Project
Well if they have given you their work, get them to explain it.
-
March 6th, 2010, 10:53 AM
#5
Re: chatting Project
hey man try to understand!!
i need help.
-
March 6th, 2010, 11:07 AM
#6
Re: chatting Project
hey man try to understand!!
i need help.
Oh I do understand, you are trying to pass someone else's work off as your own. That is plagerism, which is not only immoral, unethical and to put it bluntly cheating but can (and should) result in expulsion from your course.
If you want help, post your own work and explain where you are stuck and someone will try to help.
-
March 6th, 2010, 11:19 AM
#7
Re: chatting Project
my friend may be you are right.
no Actually you ARE right. yes this is not my work totally. i agree.
i don't have that much brains in me.
i have purchased it from the market ethically by paying its price.
which i think might be unjust to the one who created it actually and if it was really the reason then how come they are doing it legally.
ok brother that's my reason and this how i have putted it.
i could have understood all by me but the thing is i don't have time to search the whole net and take all that tutorials just to understand it.
this project will cost me 200 marks and i am in my final year.
this is my justification to your allegations.
i am not telling you to help me, if you don't want to.
knowledge can be found everywhere, the thing is where i will find it and from whom.
-
March 6th, 2010, 12:16 PM
#8
Re: chatting Project
You can justify it however you want but it's still cheating and I won't help anyone cheat and I'm sure that also goes for all the other regular contributors here.
Not completing this project may cost you 200 marks but getting caught will cost you a whole lot more.
-
March 6th, 2010, 12:20 PM
#9
-
March 6th, 2010, 12:24 PM
#10
Re: chatting Project
i appreciate your honesty.
thank you for replying.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|