Click here to Skip to main content
13,291,690 members (56,385 online)
Click here to Skip to main content
Add your own
alternative version


87 bookmarked
Posted 1 Nov 2006

Skype Game Infra

, 1 Nov 2006
Rate this:
Please Sign up or sign in to vote.
Using Skype as infrastructure for multiplayer games.

Sample Image


If you have written a nice multiplayer game, which can be played only by users on the same computer (as you never had time to even start thinking on making it online) – this article is for you. It presents a simple approach for all those “networking” tasks, and comes with a simple library implementing it. So make you game online in five minutes (well, probably two hours).


Making online games

For this discussion, I want to divide this task to two separate parts:

  1. create desktop game and
  2. allow users to play online.

The first part is interesting and difficult by itself, but is totally out of the scope of current article. For example, for chess game it includes UI and game engine that will allow two people to play chess on same computer. For my demo application, I use great chess board control, created by Gregory Prentice. In addition to the nice UI, it has a fully functional chess engine which validates the moves, fires events both for UI changes (move) and game notifications (Mate!), and so on. You can read its description here, or download the most recent version from here.

Let’s look deeper into the second task – going online. Here we should look separately at:

  1. connecting users and
  2. supplying additional online services.

Opening connection between two users:

  • server-less. Connect directly to other user’s IP? Ugly and won’t work in many cases, where the user does not have external IP address (you can’t play at work!). And this is just for finding the opponent IP, take into account the firewalls, and you will see that this solution is useless in many cases.
  • with dedicated server. Obvious advantages: all users connect to known gaming server, they can see who is online etc. Building such server from a scratch is very problematic and time-consuming task. Even if you are using some existing code (for example, I saw online games based on IRC protocol), you need to manage an online server with known IP address – not something each one wants to do.

Additional services include chat window, which is a must for a game, and optionally other communication channels – voice over IP, video, etc.

Well, currently this all seems very complicated.

Using Skype as infrastructure

As you can already guess, this paragraph will explain how Skype can ease all those tasks.


I started using Skype couple of years ago for VOIP – talking to my friends and family in different countries in great sound quality. Over the time they added chat and video functionality, including conference calls.

Similar to other programs of this type, you create Skype account, mange list of contacts, see when each of your friends is online etc.

Skype API

In addition to those features, there’s a Skype Public API, which allows developing new application based on Skype capabilities. The API gives full access to all basic functionality: contacts, chats, voice calls etc. Current solution is mostly based “Application Streams” – data channels which can be created between 3rd-party applications.

Next section describes Skype API in more details. But the concept should be already clear – we will use those data streams to exchange game-specific info between players which will be all connected to Skype. This approach solves most of the difficulties in making online games:

  • All users are logged in to Skype servers and you don’t need to worry about the network layer but can use reliable connection to exchange data
  • You always know who is connected to Skype at any moment
  • Chat window, voice conversations and even video calls are available in Skype

Using Skype API

This section describes basic Skype API and a COM API, when special attention is given to topics related to “Application Streams”. The API is well documented, and can be found here. You can also use developers' forum to find answers on subjects that are not explained well in the documentation.

In the next section you can find description of SkypeGameInfra library, which wraps all relevant functionality in convenient way. You can even skip current section for now, and go back to it only when you need to get more details, or make changes.

Skype API for Windows

Application exchanges data with Skype using WM_COPYDATA Windows messages. The format of the messages is called “Skype Protocol”, which defines set of commands that can be sent to Skype. Full description of commands can be found here.


In addition to Skype API, which isn’t very friendly to use, there’s a COM wrapper which represents the Skype API as COM objects with properties and events. Again, full description can be found here. I will describe the parts relevant for creating “Application Streams”.

  1. Skype is the top-level object. To create an instance:
    SKYPE4COMLib.Skype skype = new SKYPE4COMLib.Skype();

    This operation will pop-up a message in Skype, saying to the user that new application is attaching. The user should allow this operation (it’s recommended to use the “never ask again” option).

    Note: if by mistake you’ve disabled your application from using Skype, you can go to C:\Documents and Settings\WINDOWS USER NAME\Application Data\Skype\SKYPE USER NAME, and find your application in config.xml, UI/AccessControlList/ClientX node – just delete this whole node (make sure the numbering of Client nodes remains correct)

  2. In order to check whether you could connect to Skype, test AttachmentStatus property:
    SKYPE4COMLib.ISkype iskype = skype as SKYPE4COMLib.ISkype;
    if (iskype.AttachmentStatus == 
        { /* error */ }    
  3. Next you have to register your application. Each “application” connected to Skype has a unique name, by which it can be identified.
    SKYPE4COMLib.Application app = 
    if (app != null) {
  4. And we also need to register on two events: ApplicationStreams and ApplicationReceiving.
    skype.ApplicationStreams += new 
    skype.ApplicationReceiving += new 
  5. When you are ready to open connection to another Skype user, just call:
    app.Connect(skypeHandle, false);
    // skypeHandle is just Skype username
    // of the user you want to connect to

    Note: The connection is received by application registered with the same APPLICATION_NAME as your application. If no such application was registered, no connection will be opened.

  6. When the connection is finally established, you will receive ApplicationStreams notification, and from now on you can use the stream to send and receive messages.
    void skype_ApplicationStreams(SKYPE4COMLib.Application pApp, 
         SKYPE4COMLib.ApplicationStreamCollection pStreams)
        SKYPE4COMLib.ApplicationStream stream = null;
        foreach (SKYPE4COMLib.ApplicationStream 
                 astream in pStreams)
            if (stream == null)
                stream = astream;

  7. To send a message just call:
    stream.Write("My message");    
  8. And, finally, messages are received through ApplicationReceiving events:
    void skype_ApplicationReceiving(SKYPE4COMLib.Application pApp, 
         SKYPE4COMLib.ApplicationStreamCollection pStreams)
        foreach (SKYPE4COMLib.ApplicationStream 
                 astream in pStreams) {
            string msg = astream.Read();
            // process message

    As an example, see the GameCommunications class in the SkypeGameInfra project.

Skype Contact List control

In addition to those APIs you can use one of two ActiveX controls to automatically get list of contacts defined in Skype: “SkypeContactList” and “SkypeContactCombo”. The use of those controls is pretty self-explanatory – just add one of them to your Form.

They can be downloaded from here - “Skype ActiveX Tools”

SkypeGameInfra wrapper

It’s .NET wrapper on top of Skype COM API which encapsulates all functionality needed for a game between 2 players.

DemoSkypeChess is an example project which uses this API.

  1. Creating new instance:
    SkypeGameInfra.GameCommunication skypeWrapper = 
          new SkypeGameInfra.GameCommunication("DemoChess");

    Note: replace “DemoChess” with your unique name

  2. Let’s say the user is connected as Alex in Skype. To invite other Skype user to a game, call:
    string username = skypeWrapper.SelectUser();
    if (username.Length > 0)

    SelectUser opens a dialog with list of all contacts, and the user should select one of them. InviteOpponent opens “Application Stream”, and sends an invitation to selected contact.

  3. At this point, your application on the remote computer (let’s say, Bob’s), which have also performed step 1 of creating GameCommunication object with same name, will receive InvitationReceived event. In the application level you will, probably, want to show a nice dialog to the user, asking to accept or decline the game.
  4. Based on Bob’s action in step 3 AcceptGame of DeclineGame should be called, and Alex will receive OpponentAccepted or OpponentDeclined event. Starting from this point the communication channel is established: Alex plays white, and Bob – black.
  5. Each player in his turn should make a move, resulting in following call:

    position parameter is arbitrary game-specific string, which will be received by the other side in OpponentMove event.

  6. Finally, the game ends when one of the parties is invoking StopGame function. This will release the “Application Steam” channel for both users, and bring the system back to the state it was after sep 1.


Chess control by Gregory Prentice:

Skype links:


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


About the Author

Michael Gopshtein
Web Developer
Israel Israel
No Biography provided

You may also be interested in...

Comments and Discussions

QuestionCan't able to run, Pin
Vinish Kumar26-Jul-13 1:22
memberVinish Kumar26-Jul-13 1:22 
Generalgreat article! Pin
iamveritas26-Feb-12 14:09
memberiamveritas26-Feb-12 14:09 
GeneralGreat Idea Pin
SamNaseri1-Nov-11 15:24
memberSamNaseri1-Nov-11 15:24 
General[Message Deleted] Pin
it.ragester28-Mar-09 6:35
memberit.ragester28-Mar-09 6:35 
GeneralExcellent Sample [modified] Pin
Oleksiy Sokolovskiy17-Jul-08 17:50
memberOleksiy Sokolovskiy17-Jul-08 17:50 
Generalabout skype API Pin
marcelaviles8-May-08 5:58
membermarcelaviles8-May-08 5:58 
GeneralRe: about skype API Pin
Michael Gopshtein8-May-08 7:07
memberMichael Gopshtein8-May-08 7:07 
QuestionStream Pin
freediver21113-Dec-07 17:29
memberfreediver21113-Dec-07 17:29 
AnswerRe: Stream Pin
RobinBlood8-Jun-08 2:52
memberRobinBlood8-Jun-08 2:52 
GeneralThis is great! Pin
cairoso20-Aug-07 17:21
membercairoso20-Aug-07 17:21 
GeneralCool indeed! Pin
zeev.blac14-Aug-07 22:33
memberzeev.blac14-Aug-07 22:33 
GeneralThanks Pin
himalayantravel19-Apr-07 9:20
memberhimalayantravel19-Apr-07 9:20 
QuestionWhy? Pin
ALEXNG8811-Apr-07 23:45
memberALEXNG8811-Apr-07 23:45 
AnswerRe: Why? Pin
Michael Gopshtein12-Apr-07 0:04
memberMichael Gopshtein12-Apr-07 0:04 
You don't need the game to make the calls, it's the opposite way - you use Skype as infrastructure for your game.

As in this article's examle, assume you want to build a chess game, to play with your opponent over the internet. How do you connect to remote computer? One of possible ways is using Skype API, as described here.
GeneralRe: Why? Pin
ALEXNG8819-Apr-07 0:19
memberALEXNG8819-Apr-07 0:19 
GeneralRe: Why? Pin
Michael Gopshtein19-Apr-07 6:34
memberMichael Gopshtein19-Apr-07 6:34 
GeneralRe: Why? Pin
ALEXNG8819-Apr-07 8:14
memberALEXNG8819-Apr-07 8:14 
GeneralCool! Pin
Steve Echols1-Nov-06 20:21
memberSteve Echols1-Nov-06 20:21 

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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.171207.1 | Last Updated 1 Nov 2006
Article Copyright 2006 by Michael Gopshtein
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid