Advertisement
szymski

Client

Apr 9th, 2014
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.12 KB | None | 0 0
  1. using Lidgren.Network;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using Tao.OpenGl;
  7.  
  8. namespace Client
  9. {
  10.     public class Client
  11.     {
  12.         public Graphics graphics;
  13.         public NetClient netClient;
  14.  
  15.         public Client()
  16.         {
  17.             graphics = new Graphics();
  18.            
  19.             NetPeerConfiguration conf = new NetPeerConfiguration("2dgame");
  20.             netClient = new NetClient(conf);
  21.             netClient.Start();
  22.             netClient.Connect("127.0.0.1", 666);
  23.             while (netClient.ServerConnection == null) { }
  24.  
  25.             NetOutgoingMessage msg = netClient.CreateMessage();
  26.             msg.Write((byte)0x01);
  27.             msg.Write("Szymski");
  28.             netClient.SendMessage(msg, NetDeliveryMethod.ReliableOrdered);
  29.  
  30.             while (true)
  31.             {
  32.                 NetIncomingMessage m;
  33.                 while ((m = netClient.ReadMessage()) != null)
  34.                 {
  35.                     if (m.MessageType == NetIncomingMessageType.Data)
  36.                     {
  37.                         byte packetId = m.ReadByte();
  38.                         switch (packetId)
  39.                         {
  40.                             case 0x10:
  41.                                 Console.WriteLine(m.ReadString());
  42.                                 break;
  43.                         }
  44.                     }
  45.                 }
  46.  
  47.                 graphics.window.DispatchEvents();
  48.  
  49.                 Gl.glClearColor(0.2f, 0.2f, 0.2f, 1f);
  50.                 Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT);
  51.  
  52.                 graphics.window.Display();
  53.             }
  54.         }
  55.  
  56.         #region Singleton
  57.         private static Client instance;
  58.  
  59.         public static void CreateInstance()
  60.         {
  61.             instance = new Client();
  62.         }
  63.  
  64.         public static Client Instance
  65.         {
  66.             get
  67.             {
  68.                 if (instance == null)
  69.                 {
  70.                     instance = new Client();
  71.                 }
  72.                 return instance;
  73.             }
  74.         }
  75.         #endregion
  76.     }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement