Results 1 to 2 of 2
- 11-07-2007, 02:33 PM #1Member
- Join Date
- Nov 2007
- Rep Power
Multithreading + Networking (desperate)
i'm trying to implement a simple p2p server.
the server should listen on a port for incoming connection and when there is it launches a new thread which will accept the connection and open a TCP port with this client.
before anything the client should send his username and version of prog he is using.
1- how can i implement threading that will allow to many users to connect to this server at the same time. (how will i differentiate between them if they use the same socket).
2- if the user send his username ... i store this in a string on the server and check for it, then he sends his password how will i check, will i override the prev string ( how will i know that the name ended and the password started)
Please helppp !!!!!!
- 11-07-2007, 03:14 PM #2
Check this tutorial:
Writing the Server Side of a Socket (The Java™ Tutorials > Custom Networking > All About Sockets)
All you want is described in this tutorial in a step by step manner.
1. For handling multiple clients, check "Supporting Multiple Clients" section.
2. For username/passowrd, you will need t oimplement your own protocol just like they implemented The Knock Knock Protocol. In the first stage, you should accept the username. For example, you can have a predefined string for each command (e.g. PASS for password and USER for username) and your client can send that that string before user/pass. But note that all depend on your decisions: If you define to send password first before the username, that is a solution too!
- By tim in forum New To JavaReplies: 7Last Post: 07-16-2009, 11:43 PM
- By Java Tutorial in forum Java TutorialReplies: 0Last Post: 12-27-2007, 07:19 PM
- By Java Tutorial in forum Java TutorialReplies: 0Last Post: 12-24-2007, 08:21 PM