Hi, I was working on a chat program with multiple connections where every client connects to one server which is always running. But, I could not get the messages sent from the server to the client since they are different programs.
I've attached my client code and my server code if someone wants to help. (The 2 codes are not long btw.)
What do you mean? Since server and client are 2 different programs and I want to send the messages to the client then how will I put that under server? There's no way of saying send data to a msgbox in a different program.....unless you know how?
Basicly your client application will not change whatsoever!
Heres how we will set up your chat application,
Server listens with Winsock(0), when clients connects it loads a new winsock and connects to the client Winsock(x).
Now then the client sends chat data to the server just liek in your 2 way chat, and the server acts as a big trampoline (haha) and all it does is rebounds the text to all of the connected clients.
so....
In your servers dataarrival event,
VB Code:
Private Sub Winsock_DataArrival(index As Integer, ByVal bytesTotal As Long)
Dim strData As String
Winsock(index).GetData strData
For i = 0 to winsock.ubound - 1
if winsock(i).state = sckConnected then
winsock(i).senddata strData
end if
doevents
Next I
end sub
Make any more sence? I have a project I wrote a while ago i'lls ee if I can find it for you
1. You put that I should change the listbox thing. How can I put it so when someone connects it shows the nickname in the listbox? I really can't figure that out.
Ok, well the way I do things like this is when a client connects to the server you send a command like,
"!,NickNameHere"
Then when the server recieves data it checks to see if the left most character is a ! if it is, we have a new user and the server send sit to the clients
It gets a bit complex but look at the server example i posted (look at my data arrival event)