?
Solved

Chat Server Application

Posted on 2003-03-05
2
Medium Priority
?
884 Views
Last Modified: 2013-11-13
I am developing a chat application using VB6, which has to run its server on COM+/DCOM on a remote machine. Whenever a client starts, the server object is instantiated. I don't want it to create an instance for each client. What should I do? Also please put up some valuable suggestions for the app.
0
Comment
Question by:shibu_shaji
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 

Accepted Solution

by:
Avince earned 200 total points
ID: 8072879
The WinSock control is a great tool for something like this.  The MSDN files for WinSock have some sample code that can be used for a chat application. TCP or UDP can be used. Try UDP for peer-to-peer chat, TCP is all chats go through a central server. UDP example from MSDN excerpted below.
---------------------------------------
UDP Basics
Creating a UDP application is even simpler than creating a TCP application because the UDP protocol doesn't require an explicit connection. In the TCP application above, one Winsock control must explicitly be set to "listen," while the other must initiate a connection with the Connect method.

In contrast, the UDP protocol doesn't require an explicit connection. To send data between two controls, three steps must be completed (on both sides of the connection):

Set the RemoteHost property to the name of the other computer.


Set the RemotePort property to the LocalPort property of the second control.


Invoke the Bind method specifying the LocalPort to be used. (This method is discussed in greater detail below.)
Because both computers can be considered "equal" in the relationship, it could be called a peer-to-peer application. To demonstrate this, the code below creates a "chat" application that allows two people to "talk" in real time to each other:

To create a UDP Peer

Create a new Standard EXE project.


Change the name of the default form to frmPeerA.


Change the caption of the form to "Peer A."


Draw a Winsock control on the form and name it udpPeerA.


On the Properties page, click Protocol and change the protocol to UDPProtocol.


Add two TextBox controls to the form. Name the first txtSend, and the second txtOutput.


Add the code below to the form.
Private Sub Form_Load()
    ' The control's name is udpPeerA
    With udpPeerA
        ' IMPORTANT: be sure to change the RemoteHost
        ' value to the name of your computer.
        .RemoteHost= "PeerB"
        .RemotePort = 1001   ' Port to connect to.
        .Bind 1002                ' Bind to the local port.
    End With
    frmPeerB.Show                 ' Show the second form.
End Sub

Private Sub txtSend_Change()
    ' Send text as soon as it's typed.
    udpPeerA.SendData txtSend.Text
End Sub

Private Sub udpPeerA_DataArrival _
(ByVal bytesTotal As Long)
    Dim strData As String
    udpPeerA.GetData strData
    txtOutput.Text = strData
End Sub

To create a second UDP Peer

Add a standard form to the project.


Change the name of the form to frmPeerB.


Change the caption of the form to "Peer B."


Draw a Winsock control on the form and name it udpPeerB.


On the Properties page, click Protocol and change the protocol to UDPProtocol.


Add two TextBox controls to the form. Name the TextBox txtSend, and the second txtOutput.


Add the code below to the form.
Private Sub Form_Load()
    ' The control's name is udpPeerB.
    With udpPeerB
        ' IMPORTANT: be sure to change the RemoteHost
        ' value to the name of your computer.
        .RemoteHost= "PeerA"
        .RemotePort = 1002    ' Port to connect to.
        .Bind 1001                ' Bind to the local port.
    End With
End Sub

Private Sub txtSend_Change()
    ' Send text as soon as it's typed.
    udpPeerB.SendData txtSend.Text
End Sub

Private Sub udpPeerB_DataArrival _
(ByVal bytesTotal As Long)
    Dim strData As String
    udpPeerB.GetData strData
    txtOutput.Text = strData
End Sub

To try the example, press F5 to run the project, and type into the txtSend TextBox on either form. The text you type will appear in the txtOutput TextBox on the other form.

0
 
LVL 49

Expert Comment

by:DanRollins
ID: 9046920
Hi shibu_shaji,
It appears that you have forgotten to close 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:

    Accept Avince's comment(s) as an answer.

shibu_shaji, 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.
==========
DanRollins -- EE database cleanup volunteer
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question