multiple connection for chating using winsock in vb

jinijose used Ask the Experts™
can any one give me an example for multiple connection request for a chat programme in vb ?
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Give More Points i will give you a running application
1) Create a main form frmMain with your server winsock control. In your form load bind a port to the winsock control then set the control listening. Also dimension Clients as New Collection

2) Create a duumy form with another winsock control on it all it frmClient. In a Global module declare ClientID as Long.

3) When a new client tries to connect to the server do the following in the frmMain Winsock1_ConnectionRequest:

Private Sub Winsock1_ConnectionRequest(ByVal requestID As Long)

Dim FRM as frmClient
set frm=new frmclient

' a global counter for each new client
Clients.Add frm,cstr(ClientID)
frm.Winsock1.Accept requestID
set frm = nothing

End Sub

4) When the client sends you data it comes in on frmClient Winsock1_DataArrival.

So you know the clientID so you can send to all others like this in the data arrival event, or queue it to another process using a time control (which is better).

Dim Client as form
For Each Client in Clients
    IF Client.ClientID<>ClientID Then
       Client.SendData "......"
    End if

5) When a clients hands up then you can do the following in frmClient:

Private Sub Winsock1_Close()
    Clients.Remove cstr(ClientID)
End Sub

Hope this helps :~)
Further improvment regarding thread management.....It would be best to use a project type of ActiveX EXE and use the "One Thread pe Object" option.

You can queue data arrival events to aonther process.  When the full data from the client has come in. You know this becuase you make the client send a terminator like "{$END}".  When frmClient finds this terminator it can save the data into an array or collection like this:

MessageCount = MessageCount +1
Messages.Add Cstr(MessageCount) + "|" + cstr(ClientID) + "|" + Message

frmAnotherForm.timerMessages.Interval = 1

This means that another thread will send out the messages, leaving the frmClient available to hand another message from the client.

Ensure you’re charging the right price for your IT

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!


Top Expert 2012

Two points you may want to consider:
1. You may find Experts more receptive if you take the time to explain in detail what you need.  Writing in all caps will not help you get a solution any faster and turns Experts off, as it looks like you are yelling.

2. Please maintain your open question at:

Hi jinijose do you still need any further help with the TCP/IP project? Your question indicates that you already know about winsock and that you just need help with multiple connection requests.  You have already been given all you need, but as rajesh79 suggested, what do you expect for just 100 points?  We all have jobs to do and mortgages to pay but want to help too.  So take acperkins's advice and give us a clue what else you need! Maybe we can help :~)
This looks like it might be a good example:


Thanks Anthony, Thanks for your advice. I will respect your words and i should follow that words.

Thank you.

Author of the Year 2009

Hi jinijose,
It appears that you have forgotten this question. I will ask Community Support to close it unless you finalize it within 7 days. I will ask a Community Support Moderator to:

    Split points between: inthedark and vinnyd79

jinijose, if you think your question was not answered at all or if you need help, just post a new comment here; Community Support will help you.  DO NOT accept THIS comment as an answer.

EXPERTS: If you disagree with that recommendation, please post an explanatory comment.
DanRollins -- EE database cleanup volunteer

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial