Results 1 to 2 of 2

Thread: Client x Server Communication { Easy Question }

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jul 2006
    Posts
    26

    Talking Client x Server Communication { Easy Question }

    Hello =)


    I'd like to know how can i identificate who sent the last "data" arrived.

    For exemple:


    A server is running...

    then, a client connect to the server and asks for a DOWNLOAD.

    BUT, there's millions of clients connected at the same time, so, how can i know WICH client sent to me a file request?


    and how can i send a message directly to the server?? and to another specified client?? =D



    thx



  2. #2
    Lively Member
    Join Date
    Oct 2006
    Posts
    81

    Re: Client x Server Communication { Easy Question }

    Client identifyer is winsock index, working with winsock arrays is easy, in any winsock sub there will be argument "Index As Integer", So when you need to send data to specified client you use Winsock1(Index).SendData "DataHere".

    To identicate who sent the last data you can use a variable (Dim strLastWhoSent as String) and update it with the clients IP address when it requests a file from server.

    For example:

    VB Code:
    1. Option Explicit
    2. Dim strLastWhoSent as String
    3.  
    4. Private Sub Winsock1_DataArrival(Index As Integer, ByVal bytesTotal As Long)
    5. Dim sData As String
    6. Winsock1(Index).GetData sData
    7.  
    8. 'need to parse the request here...
    9. 'when its parsed you can select case or just use "IF .. " function to check what data was sent, and reply
    10.  
    11. If instr(sData,"GET ..... /yourfile.exe for example")<>0 then
    12. 'start to send the file..
    13. 'for now this is the last client who sent the file request, so update the strLastWhoSent
    14. strLastWhoSent=Winsock1(index).RemoteHostIP   'the clients ip address
    15. 'You send to client that request is accepted for example..
    16. Winsock1(index).SendData "bla bla bla accepted!"
    17. end if
    18.  
    19. End Sub
    Well hope this helps for you, if that is what you ment..

    /Jean

    Edit: forgot the vbcode brackets..

Posting Permissions

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



Click Here to Expand Forum to Full Width