Results 1 to 25 of 25

Thread: [RESOLVED] New Problem Getting Peoples Nicknames

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2005
    Posts
    73

    Resolved [RESOLVED] New Problem Getting Peoples Nicknames

    my program is now running smoothly with very little errors now and even multiple connections but i was wondering in have a list box on my form and i was wondering how i can make everyone who is connected to my server show up in it


    -BladeZ

  2. #2
    Lively Member
    Join Date
    Jul 2005
    Location
    Belgium
    Posts
    68

    Re: New Problem Getting Peoples Nicknames

    Simply let the clients send their nicknames to the server when they connect, and then let the server send the whole bunch of nicknames to all the clients every time something changes.
    Then let the client just go through the string or array and add all the names to a listbox.

    Don't really see a problem.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jul 2005
    Posts
    73

    Re: New Problem Getting Peoples Nicknames

    yes i know that but how can i check to see if the data that is coming into the server is a nickname or a msg

  4. #4
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: New Problem Getting Peoples Nicknames

    Add #xxxxx# to the front of the data. So that every message has a nickname attached to it. You'd have to change the client and server. Look at woka's msn client in codebank. See how it works.

  5. #5

    Thread Starter
    Lively Member
    Join Date
    Jul 2005
    Posts
    73

    Re: New Problem Getting Peoples Nicknames

    i do this is it look


    VB Code:
    1. Public Sub winsock_connect()
    2. MsgBox "You Are Now Connected "
    3. Winsock.SendData "N:" & frmlogin.txtnick.Text
    4. txtchat.Text = " "
    5. End Sub
    6.  
    7.  
    8.  
    9.  
    10. Private Sub cmdSend_click()
    11. Winsock.SendData frmlogin.txtnick.Text & ": " & txtmsg.Text
    12. 'txtchat.Text = txtchat.Text & vbNewLine & frmlogin.txtnick.Text & ": " & txtmsg.Text
    13. txtmsg.Text = ""
    14. end sub


    server does this

    VB Code:
    1. If strRecivedData = "N:" Then
    2. txtchat.Text = strRecivedData & " has joined chat."
    3. server(SocketCheck).SendData ""

  6. #6
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: New Problem Getting Peoples Nicknames

    When the user connects, you could try this:
    This will call the addit() sub, and pass the current username. The addit() sub will loop through the current contents of the listbox, and if the name isn't there, then it will add it. You might want to do something if the user changes their nickname, so that both don't appear. You'd have to remove the old name, and then add the current nickname. Just add a removeit() sub,

    Declare a dynamic array and add list1 as a listbox

    VB Code:
    1. DIM arr() as string ' to split up the data
    2.  
    3. If strRecivedData = "N:" Then
    4.   txtchat.Text = strRecivedData & " has joined chat."
    5.   arr() = split(strRecivedData,":")
    6.   call addit(arr(0))
    7.   server(SocketCheck).SendData ""
    8. end if
    9. end sub
    10.  
    11. Sub addit(x As String)
    12.   Dim a As Integer
    13.   For a = 0 To List1.ListCount - 1
    14.     If x = List1.List(a) Then Exit Sub
    15.   Next a
    16.   List1.AddItem x
    17. End Sub

  7. #7
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: New Problem Getting Peoples Nicknames

    I wrote this to test it. Try it by itself. It won't allow dups.
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4. Call addit("david")
    5. Call addit("noteme")
    6. Call addit("david")
    7. Call addit("david")
    8. Call addit("noteme")
    9. Call addit("david")
    10. Call addit("sam")
    11. Call addit("david")
    12. End Sub
    13.  
    14. Sub addit(x As String)
    15.   Dim a As Integer
    16.   For a = 0 To List1.ListCount - 1
    17.     If x = List1.List(a) Then Exit Sub
    18.   Next a
    19.   List1.AddItem x
    20. End Sub

  8. #8

    Thread Starter
    Lively Member
    Join Date
    Jul 2005
    Posts
    73

    Re: New Problem Getting Peoples Nicknames

    for some reason its not adding the people to the list do i make it a array?


    can you tell me how to check if there is a N: infront of it and if there is do addit

    VB Code:
    1. Private Sub Server_DataArrival(Index As Integer, ByVal bytesTotal As Long)
    2.  
    3. Dim strRecivedData As String
    4. Dim SocketCheck As Integer
    5.  
    6.  
    7. server(Index).GetData strRecivedData
    8. txtchat.Text = txtchat.Text & vbNewLine & strRecivedData
    9. If strRecivedData = "N:" Then
    10.   txtchat.Text = strRecivedData & " has joined chat."
    11.   arr() = Split(strRecivedData, ":")
    12.   Call addit(arr(0))
    13.   server(SocketCheck).SendData ""
    14. End If
    15. For SocketCheck = 0 To SocketCount Step 1
    16.         If server(SocketCheck).State = sckConnected Then
    17.                 server(SocketCheck).SendData strRecivedData
    18.                 DoEvents
    19.         End If
    20. Next SocketCheck
    21.  
    22. End Sub
    Last edited by BladeZ; Jul 17th, 2005 at 12:48 AM.

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Jul 2005
    Posts
    73

    Re: New Problem Getting Peoples Nicknames

    i edited my previous post

  10. #10
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: New Problem Getting Peoples Nicknames

    Did you split the line like I did? And did you declare Arr() as String so that it is accesssible to the sub? If you have different forms, you will have to declare it in a module. You could put the subroutine in the same module, too.

    Oops. Wait a sec. You'll only get "N" in the list. One time.

    Change this line:
    VB Code:
    1. Call addit(arr(0))
    to this
    VB Code:
    1. Call addit(arr(1))



    and mark your other thread as resolved, too

  11. #11

    Thread Starter
    Lively Member
    Join Date
    Jul 2005
    Posts
    73

    Re: New Problem Getting Peoples Nicknames

    ok thanks i will

  12. #12
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: [RESOLVED] New Problem Getting Peoples Nicknames

    So, it's ok, now?

  13. #13

    Thread Starter
    Lively Member
    Join Date
    Jul 2005
    Posts
    73

    Re: [RESOLVED] New Problem Getting Peoples Nicknames

    well sorta check the pm i sent you for full details

  14. #14
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: [RESOLVED] New Problem Getting Peoples Nicknames

    You are going to have to post your code. We'll look at it later on.

  15. #15

    Thread Starter
    Lively Member
    Join Date
    Jul 2005
    Posts
    73

    Re: [RESOLVED] New Problem Getting Peoples Nicknames

    k i will post the server and client

    Server
    VB Code:
    1. Option Explicit
    2. Dim incommingData As String
    3. Private intMax As Long
    4. Dim SocketCount As Integer
    5. Dim TotalUsersConnected As Integer
    6. Dim arr() As String
    7.  
    8.  
    9.  
    10. Private Sub Server_ConnectionRequest(Index As Integer, ByVal requestID As Long)
    11. SocketCount = SocketCount + 1
    12. Load server(SocketCount)
    13. server(SocketCount).Accept requestID
    14. TotalUsersConnected = TotalUsersConnected + 1
    15. lblnum.Caption = "Total users connected: " & TotalUsersConnected - 1
    16.  
    17. End Sub
    18.  
    19. Private Sub Server_DataArrival(Index As Integer, ByVal bytesTotal As Long)
    20.  
    21. Dim strRecivedData As String
    22. Dim SocketCheck As Integer
    23.  
    24. server(Index).GetData strRecivedData
    25. txtchat.Text = txtchat.Text & vbNewLine & strRecivedData
    26. If strRecivedData = "N:" Then
    27.   txtchat.Text = strRecivedData & " has joined chat."
    28.   arr() = Split(strRecivedData, ":")
    29.   Call addit(arr(0))
    30.   server(SocketCheck).SendData ""
    31. End If
    32. For SocketCheck = 0 To SocketCount Step 1
    33.         If server(SocketCheck).State = sckConnected Then
    34.                 server(SocketCheck).SendData strRecivedData
    35.                 DoEvents
    36.         End If
    37. Next SocketCheck
    38.  
    39. End Sub
    40.  
    41. Private Sub cmdexit_Click()
    42. End
    43. End Sub
    44.  
    45. Private Sub form_Load()
    46. server(0).LocalPort = 7777
    47. server(0).Listen
    48. timsave.Enabled = True
    49. End Sub
    50.  
    51.  
    52.  
    53.  
    54. Private Sub timsave_Timer()
    55.  
    56. Open "C:\ServerLog.txt" For Append As #1
    57. Print #1, txtchat.Text
    58. Close #1
    59.  
    60. End Sub
    61.  
    62. Sub addit(x As String)
    63.   Dim a As Integer
    64.   For a = 0 To lstusers.ListCount - 1
    65.     If x = lstusers.List(a) Then Exit Sub
    66.   Next a
    67.   lstusers.AddItem x
    68. End Sub

    Client
    VB Code:
    1. Option Explicit
    2. Dim incommingData As String
    3.  
    4.  
    5. Private Sub Form_Load()
    6. frmchat.Visible = False
    7. frmlogin.Visible = True
    8. End Sub
    9.  
    10. Private Sub Form_Unload(Cancel As Integer)
    11. Winsock.Close
    12. End Sub
    13.  
    14. Public Sub winsock_connect()
    15. MsgBox "You Are Now Connected "
    16. Winsock.SendData "N:" & frmlogin.txtnick.Text
    17. txtchat.Text = " "
    18. End Sub
    19.  
    20. Private Sub winsock_DataArrival(ByVal bytesTotal As Long)
    21. Dim strDataRecived As String
    22. Winsock.GetData strDataRecived
    23. DoEvents
    24. txtchat.Text = txtchat.Text & strDataRecived & vbnewline
    25. End Sub
    26.  
    27. Private Sub cmdSend_click()
    28. Winsock.SendData frmlogin.txtnick.Text & ": " & txtmsg.Text  
    29. 'txtchat.Text = txtchat.Text & vbNewLine & frmlogin.txtnick.Text & ": " & txtmsg.Text
    30. txtmsg.Text = ""
    31. End Sub
    32.  
    33. Private Sub cmdexit_click()
    34.             Winsock.Close
    35. End
    36. End Sub
    37.  
    38.  
    39. Private Sub winsock_Close()
    40.     Dim sServer As String
    41.     sServer = "Server has been disconnected"
    42.     txtchat.Text = sServer & vbNewLine
    43.     Winsock.Close
    44.     MsgBox "Server is disconnected", vbCritical, "Closing Chat System"
    45.     End
    46. End Sub

  16. #16
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: [RESOLVED] New Problem Getting Peoples Nicknames

    Can't you post the project(s)?

  17. #17

    Thread Starter
    Lively Member
    Join Date
    Jul 2005
    Posts
    73

    Re: [RESOLVED] New Problem Getting Peoples Nicknames

    Quote Originally Posted by dglienna
    Can't you post the project(s)?
    ya i will dont mind some stuff thats in the client
    Attached Files Attached Files

  18. #18
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Re: [RESOLVED] New Problem Getting Peoples Nicknames

    I'll let Pino look at it tonight. If he doesn't answer, I'll try it tomorrow, although winsock isn't my strong point

  19. #19

    Thread Starter
    Lively Member
    Join Date
    Jul 2005
    Posts
    73

    Re: [RESOLVED] New Problem Getting Peoples Nicknames

    ok thanks i just hope he responds becuase i havnt seen him in awhile

  20. #20
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787

    Re: [RESOLVED] New Problem Getting Peoples Nicknames

    your missing frmpon in your client app....

    pINO

  21. #21

    Thread Starter
    Lively Member
    Join Date
    Jul 2005
    Posts
    73

    Re: [RESOLVED] New Problem Getting Peoples Nicknames

    Quote Originally Posted by Pino
    your missing frmpon in your client app....

    pINO

    just delete the refrneces to it has no use in the program

  22. #22
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787

    Re: [RESOLVED] New Problem Getting Peoples Nicknames

    hmmm.... whats sockect check is that also now obsolite?

  23. #23
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787

    Re: [RESOLVED] New Problem Getting Peoples Nicknames

    Ok i think you should have a good look at my Vb useful functions, it explains many of the strinfunctions

    change your data arrival event in you server to this...

    VB Code:
    1. Private Sub Server_DataArrival(Index As Integer, ByVal bytesTotal As Long)
    2.  
    3. Dim strRecivedData As String
    4. Dim SocketCheck As Integer
    5.  
    6. 'Recive the message from the client
    7. server(Index).GetData strRecivedData
    8. txtchat.Text = txtchat.Text & vbNewLine & strRecivedData
    9. 'What this for statement does is go through all the winsocks
    10. 'that we have open and make sure that they are connected to
    11. 'a client. If they are then send the message to the client
    12. If Left(strRecivedData, 2) = "N:" Then
    13.   txtchat.Text = strRecivedData & " has joined chat."
    14.   arr() = Split(strRecivedData, ":")
    15.   Call addit(arr(1))
    16. End If
    17.  
    18. For SocketCheck = 0 To server.UBound - 1
    19.         'If the winsocks state is Connected then send the message
    20.         'to that client.
    21.         If server(SocketCheck).State = sckConnected Then
    22.                 server(SocketCheck).SendData strRecivedData
    23.                 DoEvents
    24.         End If
    25. Next SocketCheck
    26.  
    27. End Sub

    works ok, but i have to be honest some of the code is some what messy.

    Anyhows that works now.

  24. #24

    Thread Starter
    Lively Member
    Join Date
    Jul 2005
    Posts
    73

    Re: [RESOLVED] New Problem Getting Peoples Nicknames

    pino that code works very well but now it sometimes doesnt sned text to all users eg. User 1 send HI User 2 Sees HI user 3 doesnt see anything


    !!!EDIT!!! nvm got it working
    Last edited by BladeZ; Jul 19th, 2005 at 04:38 PM.

  25. #25
    PowerPoster
    Join Date
    Dec 2003
    Posts
    4,787

    Re: [RESOLVED] New Problem Getting Peoples Nicknames


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