Click here to Skip to main content
15,891,473 members
Articles / Desktop Programming / MFC
Article

A Network Chat Program using Windows Sockets

Rate me:
Please Sign up or sign in to vote.
3.58/5 (10 votes)
29 Aug 2000 125.5K   7.2K   31   9
A program that allows users across a homogeneous network to communicate with each other using the TCP/IP protocol
  • Download source files - 65 Kb
  • Download application - 18 Kb
  • Introduction

    LanTalk is a network program that I wrote a long time ago, when I was getting the hang of Windows programming-SDK style. I found it gathering dust quite recently on my hard disk, and thought it would be a good idea to make this available to other developers, particularly for folks doing stuff with Windows sockets. I dusted it a bit and voila, you have the most recent incarnation of this useful program.

    LanTalk is basically a program that allows users across a homogeneous network to communicate with each other using the TCP/IP protocol. LanTalk uses sockets extensively, and was inspired by Win-Popup, a similar but more powerful program that was part of Windows 95 (at that time, there was no Windows 98!).

    LanTalk brings to the table a number of interesting things...sockets, fancy animation, threads...animated cursors...context sensitive help, etc.Therefore, I hope it will be a good program to look up to where you can pick up lot of pointers (no pun intended).

    How to use LanTalk:

    1. Make sure that both LanTalk.exe and the LanHelp.hlp file resides in the same folder.
    2. Run the program. Initially, the program is passive, and is not listening for connections from other LanTalk users.
    3. Click the 'Listen' button. The program now watches out for incoming connections.
    4. You can minimize LanTalk while in the 'Listen' state, by checking the option for minimizing the program. The program pops up when you have an incoming connection; you can always restore the program by clicking the icon on the task bar.
    5. When you are connected and have a message, the 'Receive' button is enabled, and the default beep sound (may vary from computer to computer) is generated. Click this 'Receive' button to get your message. The message status panel also shows you if you have an incoming message or not.

    Assuming you want to connect to another LanTalk user (for this, the other side must be running LanTalk in a 'Listen' state), do the following:

    1. Enter a computer identification name in the 'Update Host List' edit box. Then click the 'Add' button. You can get this id from Control Panel/Network/Identification tab. Do this for as many available ids on your LAN.
    2. Select any desired name from the 'Host Selected' combo box. This is the name/id you will connect to. You can delete any id by selecting it and clicking on the 'Delete' button.
    3. After selecting a valid id to connect to, click the 'Connect' button. LanTalk will try to connect to that computer on your LAN.

      If LanTalk cannot connect, it may be due to any of the following reasons:

      • The computer is not running LanTalk/not turned on.
      • There is no such computer id on the LAN.

      If the connection is successful, type in the message to be sent in the 'Messages Out' edit box and click 'Send'.

      • If LanTalk cannot send or receive a message, the reason for failure will be displayed. It is best to click 'Disconnect' and start again, in such circumstances.
      • If either end disconnects during a connected session, the other end will receive a 'LanTalk Disconnected' message.
      • You can use the context sensitive help as well-move the focus to the desired control and press F1. Alternatively, click on the '?' button located in the top right corner of the dialog. After you do so, the '?' moves along with the mouse cursor. Place the cursor over the control you need more information on, and left click.

    Some Limitations

    • User manually configures LanTalk to reflect all available computer (ids) on the LAN. This can be automated.
    • Currently only two users can be actively engaged in a connection and have a chat session. Hence, other LanTalk users cannot send messages to already connected LanTalk users.
    • The reason for the above is as follows: currently LanTalk maintains a single thread for incoming connections. This thread maintains a server socket that listens for incoming calls. Once a connection is established, the server socket in the thread is closed and the thread is terminated-this disables further connections from other users. Ideally, this thread should continue to listen with an open server socket, and once a socket connects with the listening socket, the newly binded socket should be moved to a linked list of sockets, while the original continues to listen. This way, any number of users can connect to the LanTalk server thereby, facilitating a one to many chat session. However, for this architecture there should be a single LanTalk server running, that other clients connect to, instead of the present way of having the program running on each and every machine. As of now, the program is both the client and the server.
    • The actively running program should be iconized in the system tray, rather than being available on the taskbar-and should spring to action when clicked.

    Disclaimer

    LanTalk Version 1.0. Copyright (C) 2000 by Shanker.C. All rights reserved. No warranty of any kind, expressed or implied, is included with this software; use at your own risk, responsibility for damages (if any) to anyone resulting from the use of this software rests entirely with the user.

    License

    This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

    A list of licenses authors might use can be found here


    Written By
    Australia Australia
    This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

    Comments and Discussions

     
    General[Message Deleted] Pin
    it.ragester2-Apr-09 21:48
    it.ragester2-Apr-09 21:48 
    Generalchat on the internet Pin
    black_knight8-Oct-04 2:28
    black_knight8-Oct-04 2:28 
    GeneralNew to Internet Programming Pin
    Hua Hsin9-Jun-03 21:16
    Hua Hsin9-Jun-03 21:16 
    I am new to Internet programming and I want to write a simple chat program. I have go through some of the sample but still can't create a chat program.

    My problem is in client part:
    LPHOSTENT Host;
    Host = gethostbyname("aaa");
    if(!Host)
    return; --> It suppose to not get in here. Why I reach here?

    Does these statement right or wrong?
    GeneralChat Program Pin
    2-Feb-02 8:43
    suss2-Feb-02 8:43 
    GeneralRe: Chat Program Pin
    10-Feb-02 15:07
    suss10-Feb-02 15:07 
    GeneralThis can't be lantalk ! Pin
    Paul4-Sep-00 3:49
    Paul4-Sep-00 3:49 
    GeneralRe: This can't be lantalk ! Pin
    Shankar Chandra Bose4-Sep-00 13:45
    Shankar Chandra Bose4-Sep-00 13:45 
    GeneralRe: This can't be lantalk ! Pin
    Pavel Sokolov7-Sep-00 4:03
    Pavel Sokolov7-Sep-00 4:03 
    GeneralRe: This can't be lantalk ! Pin
    Member 9627-Dec-00 10:26
    Member 9627-Dec-00 10:26 

    General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

    Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.