Results 1 to 4 of 4
Thread: Client TCP in Java
- 07-31-2007, 08:49 PM #1
Member
- Join Date
- Jul 2007
- Posts
- 40
- Rep Power
- 0
Client TCP in Java
Hi, I can get a tcp server to communicate with a client, and thread this to simultaneously communicate with more clients, but i don't know how to get the clients to be able to hear each other, i cant seem to even loop through clients to send to when i want the server to reply
Does anyone know how to do this, or have a simple tutorial on it?
Threads really confuse me.
Thanks.
- 08-01-2007, 02:29 AM #2
Member
- Join Date
- Jul 2007
- Location
- Las Vegas
- Posts
- 14
- Rep Power
- 0
Sorry, I am a bit new with Java, and I hope you don't mind me asking, but what's TCP?
May I suggest a linked list? where each client acts as a node?
- 08-07-2007, 06:34 AM #3
Member
- Join Date
- Jul 2007
- Posts
- 40
- Rep Power
- 0
Please check this code:
Java Code:public class rServerRegistrar { public Thread[] cthreads; public rServerRegistrar(Thread thr) { cthreads=new Thread[1]; cthreads[0]=thr; } public void registerThread(Thread newthread) { Thread[] tempthreads=new Thread[cthreads.length+1]; for(int i=0;i<cthreads.length;i++) { tempthreads[i]=cthreads[i]; } tempthreads[cthreads.length]=newthread; cthreads=tempthreads; } public void deregisterThread(Thread delthread) { Thread[] tempthreads=new Thread[cthreads.length-1]; int count=0; for(int i=0;i<cthreads.length;i++) { if(delthread.getName()!=cthreads[i].getName()) { tempthreads[count]=cthreads[i]; count++; } } cthreads=tempthreads; } private void updateThreads() { int count=0; // First count the number of alive threads. for(int i=0;i<cthreads.length;i++) { if(cthreads[i].isAlive()) count++; } Thread[] temp=new Thread[count]; count=0; for(int i=0;i<cthreads.length;i++) { if(cthreads[i].isAlive()) { temp[count]=cthreads[i]; count++; } } } public Thread[] getClientThreads() { updateThreads(); // Return all except first thread. Thread[] temp=new Thread[cthreads.length-1]; for(int i=0;i<temp.length;i++) { temp[i]=cthreads[i+1]; } return temp; } }
- 08-09-2007, 08:18 PM #4
Member
- Join Date
- Aug 2007
- Posts
- 30
- Rep Power
- 0
Similar Threads
-
a problem about java mail client program
By lunarstyle in forum AWT / SwingReplies: 9Last Post: 12-19-2009, 04:14 PM -
Identify Client in Socket Client Server Application
By masadjie in forum NetworkingReplies: 1Last Post: 12-20-2007, 09:18 AM -
PPPoE client programming in java
By yeadam in forum NetworkingReplies: 0Last Post: 12-03-2007, 12:14 AM -
java client
By heyhey in forum Advanced JavaReplies: 0Last Post: 10-29-2007, 05:04 PM -
Telnet client Java
By susan in forum NetworkingReplies: 1Last Post: 07-30-2007, 09:59 PM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks