Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 889
  • Last Modified:

Chat Server Application

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
shibu_shaji
Asked:
shibu_shaji
1 Solution
 
AvinceCommented:
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
 
DanRollinsCommented:
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

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now