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
Public Const MyGuid As String = _
"{8EC1E2EC-5266-11D4-811C-AD15B9B82C76}"
Public Sub CreateSession(ByRef ConnectionIndex As Long)
Set DPAddress = DPEnum.GetAddress(ConnectionIndex)
Call DP.InitializeConnection(DPAddress)
Set Session = DP.CreateSessionData
Session.SetMaxPlayers 8 Session.SetSessionName "ChatSession"
Session.SetGuidApplication MyGuid Session.SetFlags _
DPSESSION_DIRECTPLAYPROTOCOL Or DPSESSION_MIGRATEHOST
Call DP.Open(Session, DPOPEN_CREATE)
CreatePlayer
Form1.Timer1.Enabled = True
End Sub
Public Sub JoinSession()
Set Session = DPEnumSessions.GetItem(Form1.List2.ListIndex + 1)
If Session.GetMaxPlayers < Session.GetCurrentPlayers Then End
Session.SetGuidApplication MyGuid
DP.Open Session, DPOPEN_JOIN
CreatePlayer
Form1.Timer1.Enabled = True
End Sub
Public Sub CreatePlayer()
PlayerFriendly = InputBox("Nickname", "Create Player")
PlayerFormal = InputBox("Real name", "Create Player")
PlayerIDNum = _
DP.CreatePlayer(PlayerFriendly, PlayerFormal, 0, 0)
End Sub
Public Sub SendMessage()
Dim Msg As DirectPlayMessage
Set Msg = DP.CreateMessage
Msg.WriteString (PlayerFriendly & ": " & Form1.Text1.Text)
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)
Do While NumMessagesWaiting > 0
Set Msg = DP.Receive(SourceIP, TargetIP, DPRECEIVE_ALL)
Form1.List3.AddItem Msg.ReadString
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