Click here to Skip to main content
Click here to Skip to main content

Multi-Protocol Chat

, 23 Mar 2005
Rate this:
Please Sign up or sign in to vote.
With this application, you can chat with computers and different protocols.

Introduction

This application is a simple chat-application which provides the way to use different protocols (IP, Serial, Modem, IPX, ....).

Code-Blocks

Module1:

If you want, you can develop an Add-In (which is compatible with the chat) like a game to use it.

Public DX As New DirectX7
Public DP As DirectPlay4
Public DPEnum As DirectPlayEnumConnections
Public DPAddress As DirectPlayAddress
Public Session As DirectPlaySessionData
Public DPEnumSessions As DirectPlayEnumSessions

Public PlayerIDNum As Long
Public PlayerFriendly As String
Public PlayerFormal As String

'Warning: Don't use the string below for the chat.
Public Const MyGuid As String = _
      "{8EC1E2EC-5266-11D4-811C-AD15B9B82C76}"

Public Sub CreateSession(ByRef ConnectionIndex As Long)
  'with this we create a session.
  Set DPAddress = DPEnum.GetAddress(ConnectionIndex)
  Call DP.InitializeConnection(DPAddress)

  Set Session = DP.CreateSessionData
  Session.SetMaxPlayers 8 'here are only 8 chatters/players allowed
  Session.SetSessionName "ChatSession"
  Session.SetGuidApplication MyGuid 'the chat uses the created GUID
  'these 2 flags should be enough for every application.
  Session.SetFlags _
        DPSESSION_DIRECTPLAYPROTOCOL Or DPSESSION_MIGRATEHOST

  'now we create a session based on the properties we've just set.
  Call DP.Open(Session, DPOPEN_CREATE)

  CreatePlayer

  Form1.Timer1.Enabled = True
End Sub

Public Sub JoinSession()
  'here will be "discussed" which session you join
  Set Session = DPEnumSessions.GetItem(Form1.List2.ListIndex + 1)

  'check if one more player is allowed to join
  If Session.GetMaxPlayers < Session.GetCurrentPlayers Then End

  Session.SetGuidApplication MyGuid 'the chat/game uses the created GUID

  'open and join session
  DP.Open Session, DPOPEN_JOIN

  CreatePlayer

  Form1.Timer1.Enabled = True
End Sub

Public Sub CreatePlayer()
  'make attributes to the player/chatter...
  PlayerFriendly = InputBox("Nickname", "Create Player")
  PlayerFormal = InputBox("Real name", "Create Player")

  'now we create a player/chatter - the function returns an ID  
  'which we can use to identify us self... (later)
  PlayerIDNum = _
        DP.CreatePlayer(PlayerFriendly, PlayerFormal, 0, 0)
End Sub

Public Sub SendMessage()
  Dim Msg As DirectPlayMessage

  Set Msg = DP.CreateMessage

  'fill message
  Msg.WriteString (PlayerFriendly & ": " & Form1.Text1.Text)
  
  'send
  DP.SendEx PlayerIDNum, DPID_ALLPLAYERS, DPSEND_GUARANTEED, _
        Msg, 0, 0, 0

  Form1.List3.AddItem (PlayerFriendly & ": " & Form1.Text1.Text)
  Form1.Text1.Text = ("")
End Sub

Public Sub ReceiveMessage()
  Dim SourceIP As Long
  Dim TargetIP As Long
  Dim NumMessagesWaiting As Long
  Dim Msg As DirectPlayMessage
  
  NumMessagesWaiting = DP.GetMessageCount(PlayerIDNum) 'the number of waiting messages
  
  Do While NumMessagesWaiting > 0
    Set Msg = DP.Receive(SourceIP, TargetIP, DPRECEIVE_ALL)
    
    Form1.List3.AddItem Msg.ReadString
     
    'decrement number of waiting messages
    NumMessagesWaiting = NumMessagesWaiting - 1
  Loop

End Sub

I had no problems while developing this. Given here are some parts of the whole code. It's not very long and not very difficult.

History

  • 23rd March, 2005: Initial post

License

This article, along with any associated source code and files, is licensed under The GNU General Public License (GPLv3)

Share

About the Author

Konstantin Merz FFB
Web Developer
Germany Germany
My hobbies are C++(managed and not manged(i'm a total tiro at this), Visual Basic .Net, Inside Win2k, Tennis and maths.

Comments and Discussions

 
Questionusing the IPX for a game PinmemberDJFire4-Jun-08 23:16 
I was curious to know( if anyone still looks at these pages) about your lil program here... I see it has IPX capability, I currently run an online league with a game called VPH(Virtual Pool Hall), which has IPX connection in it... I was curious to know, how can I use your code above, and have it work with the VPH game so other people ( 1 vs 1) can connect with each other, rather then using TCP/IP connection...
 
If you know of a way to implement that into this program, that would be fantastic.
 
I did pop in the source files using VB 2005 EE, it works, but only the TCP/IP option will work, the IPX option wont let me connect or even create..

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

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

| Advertise | Privacy | Mobile
Web04 | 2.8.140814.1 | Last Updated 23 Mar 2005
Article Copyright 2005 by Konstantin Merz FFB
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid