MULTIPLAYER: CHAT

For the chat we will use the same old tricks. We need to create another table at the database ServerTu.mdb. The name will be: avatar2 and will have 2 columns:

  code CHAR 3
  chat CHAR 255

We write in it the lines:

00A  A:
00B  B:
before to replace the DB at our webhoster.

We need also to create new methods at the ServerDB.asmx and recreate the Tu14p.dll -like we did previously:

...
[WebMethod]
   public String WriteChatA(String  chatA) {
    OleDbConnection oConn = new  OleDbConnection();  
    oConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("/data/ServerTu.mdb");  
    oConn.Open();
    System.Data.OleDb.OleDbCommand  oCmd= new  OleDbCommand();
    oCmd = oConn.CreateCommand(); 
    oCmd.Connection = oConn;
    oCmd.CommandText = "UPDATE avatar2 SET  chat ='"+chatA+"' WHERE code='00A'"; oCmd.ExecuteNonQuery(); 
    oConn.Close();
    return "Chat updated for A";
   }   

[WebMethod]
   public String WriteChatB(String  chatB) {
     OleDbConnection oConn = new  OleDbConnection();  
     oConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("/data/ServerTu.mdb");  
    oConn.Open();
   System.Data.OleDb.OleDbCommand  oCmd= new  OleDbCommand();
   oCmd = oConn.CreateCommand(); 
   oCmd.Connection = oConn;
   oCmd.CommandText = "UPDATE avatar2 SET  chat ='"+chatB+"' WHERE code='00B'"; oCmd.ExecuteNonQuery(); 
   oConn.Close();
   return "Chat updated for B";
  }
   
 [WebMethod]
   public String ReadChatA() {
    String select = "SELECT * FROM avatar2 WHERE code='00A'";  
    OleDbConnection oConn = new  OleDbConnection();  
     oConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("/data/ServerTu.mdb");  
    oConn.Open();
    DataSet ds  = new  DataSet(); 
   OleDbDataAdapter datadapt = new  OleDbDataAdapter(select, oConn); 
    datadapt.Fill(ds, "chatA"); 
    return ds.Tables["chatA"].Rows[0]["chat"].ToString();
   oConn.Close();
   }

[WebMethod]
   public String ReadChatB() {
    String select = "SELECT * FROM avatar2 WHERE code='00B'";  
    OleDbConnection oConn = new  OleDbConnection();  
    oConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("/data/ServerTu.mdb");  
    oConn.Open();
   DataSet ds  = new  DataSet(); 
    OleDbDataAdapter datadapt = new  OleDbDataAdapter(select, oConn); 
   datadapt.Fill(ds, "chatB"); 
    return ds.Tables["chatB"].Rows[0]["chat"].ToString();
  oConn.Close();
 }
...

I know that you are thinking that we can have a better code and a better definition for the tables. It's true, but we are only trying to be simple and respecting the retrocompatibility with the previous exercices.

We will create a new variable: chat that will receive the typed message.

There are some other things we need to do but I believe that's is better that you do the download, run the application, analise the code, try to change something etc.

Create a folder having the name of the .ZIP file and download it - right-clicking the link - and unzip inside the folder :

tu43v.zip

After the compilation using the Visual C# Express, run Tu43v.exe 3 times. But "acquire" an avatar before to run another copy. Move the avatares, open the door, send some messages from one user to the other, wait the synchronization... It's not ActiveWorld but works...

NOTES: 1 - You need to liberate the firewall for the access to our webhoster, for this application. 2 - Starting the application, wait some seconds for the comunication to the server. 3 -REMEMBER THAT MANY READERS OF THIS TUTORIAL CAN BE TESTING THE APPLICATION AT HE SAME TIME AND YOU CAN HAVE SURPRISED STATUS!!!! IT'S A MULTIPLAYER DEMO !!!!!

If you like only to see the application running you don't need to do the above download. Only liberate the firewall and play this web3d application (wait the contact with the server ( at 999 that doesn't appear ), liberate the firewall etc. Wait a little more to choose an avatar.). Click this button again to create another copy of the application.Close/open the door at a copy, move the avatar, type something at chat area and send and at the new synchronization they will change their status at the other copy.:

We are doing our tests at a: Notebook DELL Latitude D600 - Intel Pentium M755 2.0 GHZ - Memory: 512 MB - VideoCard ATI Radeon 9000 32MB DDR 4xAGP - Resolution 1400x1050 - Communication: ADSL 256 kbps (Download: 45 kBps, Upload: 14 kBps)

o --- 0 --- o

OK. At this 19 lessons we tried to present the basics of the programming of web3D game using WPF and C#. Having doubts, read the SDK Documentation and try to contact the official WPF Forum at this link.

The last lesson (20) will have 3 parts and will present some concepts of the creation of web 2D games. Enjoy and thanks.


PREVIOUS LESSON NEXT LESSON
T.CONTENTS HOMEPAGE