Results 1 to 2 of 2
  1. #1
    bluebarca is offline Member
    Join Date
    Nov 2007
    Posts
    5
    Rep Power
    0

    Default 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 !!!!!!

  2. #2
    JavaBean's Avatar
    JavaBean is offline Moderator
    Join Date
    May 2007
    Posts
    1,270
    Rep Power
    9

    Default

    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!

Similar Threads

  1. Java networking.
    By tim in forum New To Java
    Replies: 7
    Last Post: 07-16-2009, 11:43 PM
  2. Java networking programming (II)
    By Java Tutorial in forum Java Tutorial
    Replies: 0
    Last Post: 12-27-2007, 07:19 PM
  3. Java networking programming (I)
    By Java Tutorial in forum Java Tutorial
    Replies: 0
    Last Post: 12-24-2007, 08:21 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •