Jul 14th, 2005, 02:42 AM
#1
Thread Starter
Lively Member
[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
Jul 16th, 2005, 03:14 PM
#2
Lively Member
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.
Jul 16th, 2005, 08:47 PM
#3
Thread Starter
Lively Member
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
Jul 16th, 2005, 11:23 PM
#4
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.
Jul 16th, 2005, 11:30 PM
#5
Thread Starter
Lively Member
Re: New Problem Getting Peoples Nicknames
i do this is it look
VB Code:
Public Sub winsock_connect()
MsgBox "You Are Now Connected "
Winsock.SendData "N:" & frmlogin.txtnick.Text
txtchat.Text = " "
End Sub
Private Sub cmdSend_click()
Winsock.SendData frmlogin.txtnick.Text & ": " & txtmsg.Text
'txtchat.Text = txtchat.Text & vbNewLine & frmlogin.txtnick.Text & ": " & txtmsg.Text
txtmsg.Text = ""
end sub
server does this
VB Code:
If strRecivedData = "N:" Then
txtchat.Text = strRecivedData & " has joined chat."
server(SocketCheck).SendData ""
Jul 17th, 2005, 12:14 AM
#6
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:
DIM arr() as string ' to split up the data
If strRecivedData = "N:" Then
txtchat.Text = strRecivedData & " has joined chat."
arr() = split(strRecivedData,":")
call addit(arr(0))
server(SocketCheck).SendData ""
end if
end sub
Sub addit(x As String)
Dim a As Integer
For a = 0 To List1.ListCount - 1
If x = List1.List(a) Then Exit Sub
Next a
List1.AddItem x
End Sub
Jul 17th, 2005, 12:22 AM
#7
Re: New Problem Getting Peoples Nicknames
I wrote this to test it. Try it by itself. It won't allow dups.
VB Code:
Option Explicit
Private Sub Form_Load()
Call addit("david")
Call addit("noteme")
Call addit("david")
Call addit("david")
Call addit("noteme")
Call addit("david")
Call addit("sam")
Call addit("david")
End Sub
Sub addit(x As String)
Dim a As Integer
For a = 0 To List1.ListCount - 1
If x = List1.List(a) Then Exit Sub
Next a
List1.AddItem x
End Sub
Jul 17th, 2005, 12:37 AM
#8
Thread Starter
Lively Member
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:
Private Sub Server_DataArrival(Index As Integer, ByVal bytesTotal As Long)
Dim strRecivedData As String
Dim SocketCheck As Integer
server(Index).GetData strRecivedData
txtchat.Text = txtchat.Text & vbNewLine & strRecivedData
If strRecivedData = "N:" Then
txtchat.Text = strRecivedData & " has joined chat."
arr() = Split(strRecivedData, ":")
Call addit(arr(0))
server(SocketCheck).SendData ""
End If
For SocketCheck = 0 To SocketCount Step 1
If server(SocketCheck).State = sckConnected Then
server(SocketCheck).SendData strRecivedData
DoEvents
End If
Next SocketCheck
End Sub
Last edited by BladeZ; Jul 17th, 2005 at 12:48 AM .
Jul 17th, 2005, 12:43 AM
#9
Thread Starter
Lively Member
Re: New Problem Getting Peoples Nicknames
i edited my previous post
Jul 17th, 2005, 12:49 AM
#10
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:
to this
and mark your other thread as resolved, too
Jul 17th, 2005, 12:54 AM
#11
Thread Starter
Lively Member
Re: New Problem Getting Peoples Nicknames
Jul 17th, 2005, 01:02 AM
#12
Re: [RESOLVED] New Problem Getting Peoples Nicknames
Jul 17th, 2005, 01:13 AM
#13
Thread Starter
Lively Member
Re: [RESOLVED] New Problem Getting Peoples Nicknames
well sorta check the pm i sent you for full details
Jul 17th, 2005, 02:56 PM
#14
Re: [RESOLVED] New Problem Getting Peoples Nicknames
You are going to have to post your code. We'll look at it later on.
Jul 17th, 2005, 10:14 PM
#15
Thread Starter
Lively Member
Re: [RESOLVED] New Problem Getting Peoples Nicknames
k i will post the server and client
Server
VB Code:
Option Explicit
Dim incommingData As String
Private intMax As Long
Dim SocketCount As Integer
Dim TotalUsersConnected As Integer
Dim arr() As String
Private Sub Server_ConnectionRequest(Index As Integer, ByVal requestID As Long)
SocketCount = SocketCount + 1
Load server(SocketCount)
server(SocketCount).Accept requestID
TotalUsersConnected = TotalUsersConnected + 1
lblnum.Caption = "Total users connected: " & TotalUsersConnected - 1
End Sub
Private Sub Server_DataArrival(Index As Integer, ByVal bytesTotal As Long)
Dim strRecivedData As String
Dim SocketCheck As Integer
server(Index).GetData strRecivedData
txtchat.Text = txtchat.Text & vbNewLine & strRecivedData
If strRecivedData = "N:" Then
txtchat.Text = strRecivedData & " has joined chat."
arr() = Split(strRecivedData, ":")
Call addit(arr(0))
server(SocketCheck).SendData ""
End If
For SocketCheck = 0 To SocketCount Step 1
If server(SocketCheck).State = sckConnected Then
server(SocketCheck).SendData strRecivedData
DoEvents
End If
Next SocketCheck
End Sub
Private Sub cmdexit_Click()
End
End Sub
Private Sub form_Load()
server(0).LocalPort = 7777
server(0).Listen
timsave.Enabled = True
End Sub
Private Sub timsave_Timer()
Open "C:\ServerLog.txt" For Append As #1
Print #1, txtchat.Text
Close #1
End Sub
Sub addit(x As String)
Dim a As Integer
For a = 0 To lstusers.ListCount - 1
If x = lstusers.List(a) Then Exit Sub
Next a
lstusers.AddItem x
End Sub
Client
VB Code:
Option Explicit
Dim incommingData As String
Private Sub Form_Load()
frmchat.Visible = False
frmlogin.Visible = True
End Sub
Private Sub Form_Unload(Cancel As Integer)
Winsock.Close
End Sub
Public Sub winsock_connect()
MsgBox "You Are Now Connected "
Winsock.SendData "N:" & frmlogin.txtnick.Text
txtchat.Text = " "
End Sub
Private Sub winsock_DataArrival(ByVal bytesTotal As Long)
Dim strDataRecived As String
Winsock.GetData strDataRecived
DoEvents
txtchat.Text = txtchat.Text & strDataRecived & vbnewline
End Sub
Private Sub cmdSend_click()
Winsock.SendData frmlogin.txtnick.Text & ": " & txtmsg.Text
'txtchat.Text = txtchat.Text & vbNewLine & frmlogin.txtnick.Text & ": " & txtmsg.Text
txtmsg.Text = ""
End Sub
Private Sub cmdexit_click()
Winsock.Close
End
End Sub
Private Sub winsock_Close()
Dim sServer As String
sServer = "Server has been disconnected"
txtchat.Text = sServer & vbNewLine
Winsock.Close
MsgBox "Server is disconnected", vbCritical, "Closing Chat System"
End
End Sub
Jul 18th, 2005, 03:33 PM
#16
Re: [RESOLVED] New Problem Getting Peoples Nicknames
Can't you post the project(s)?
Jul 18th, 2005, 05:05 PM
#17
Thread Starter
Lively Member
Re: [RESOLVED] New Problem Getting Peoples Nicknames
Originally Posted by
dglienna
Can't you post the project(s)?
ya i will dont mind some stuff thats in the client
Attached Files
Jul 18th, 2005, 07:18 PM
#18
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
Jul 18th, 2005, 07:28 PM
#19
Thread Starter
Lively Member
Re: [RESOLVED] New Problem Getting Peoples Nicknames
ok thanks i just hope he responds becuase i havnt seen him in awhile
Jul 19th, 2005, 02:28 PM
#20
Re: [RESOLVED] New Problem Getting Peoples Nicknames
your missing frmpon in your client app....
pINO
Jul 19th, 2005, 02:32 PM
#21
Thread Starter
Lively Member
Re: [RESOLVED] New Problem Getting Peoples Nicknames
Originally Posted by
Pino
your missing frmpon in your client app....
pINO
just delete the refrneces to it has no use in the program
Jul 19th, 2005, 02:39 PM
#22
Re: [RESOLVED] New Problem Getting Peoples Nicknames
hmmm.... whats sockect check is that also now obsolite?
Jul 19th, 2005, 02:44 PM
#23
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:
Private Sub Server_DataArrival(Index As Integer, ByVal bytesTotal As Long)
Dim strRecivedData As String
Dim SocketCheck As Integer
'Recive the message from the client
server(Index).GetData strRecivedData
txtchat.Text = txtchat.Text & vbNewLine & strRecivedData
'What this for statement does is go through all the winsocks
'that we have open and make sure that they are connected to
'a client. If they are then send the message to the client
If Left(strRecivedData, 2) = "N:" Then
txtchat.Text = strRecivedData & " has joined chat."
arr() = Split(strRecivedData, ":")
Call addit(arr(1))
End If
For SocketCheck = 0 To server.UBound - 1
'If the winsocks state is Connected then send the message
'to that client.
If server(SocketCheck).State = sckConnected Then
server(SocketCheck).SendData strRecivedData
DoEvents
End If
Next SocketCheck
End Sub
works ok, but i have to be honest some of the code is some what messy.
Anyhows that works now.
Jul 19th, 2005, 04:18 PM
#24
Thread Starter
Lively Member
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 .
Jul 20th, 2005, 02:49 AM
#25
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
Forum Rules
Click Here to Expand Forum to Full Width