本文整理汇总了C#中Lidgren.Network.NetPeerConfiguration.SetMessageTypeEnabled方法的典型用法代码示例。如果您正苦于以下问题:C# NetPeerConfiguration.SetMessageTypeEnabled方法的具体用法?C# NetPeerConfiguration.SetMessageTypeEnabled怎么用?C# NetPeerConfiguration.SetMessageTypeEnabled使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lidgren.Network.NetPeerConfiguration
的用法示例。
在下文中一共展示了NetPeerConfiguration.SetMessageTypeEnabled方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ClientConnection
internal ClientConnection(bool dummy)
{
if (!dummy)
{
SynchronizationContext.SetSynchronizationContext(new SynchronizationContext());
NetPeerConfiguration peerConfig = new NetPeerConfiguration("Qbes");
peerConfig.AutoFlushSendQueue = true;
peerConfig.SetMessageTypeEnabled(NetIncomingMessageType.DebugMessage, true);
peerConfig.SetMessageTypeEnabled(NetIncomingMessageType.ErrorMessage, true);
peerConfig.SetMessageTypeEnabled(NetIncomingMessageType.VerboseDebugMessage, true);
peerConfig.SetMessageTypeEnabled(NetIncomingMessageType.WarningMessage, true);
_Client = new NetClient(peerConfig);
_Client.RegisterReceivedCallback(new SendOrPostCallback(ReceivedMessage));
}
}
示例2: Program
public Program()
{
NetPeerConfiguration config = new NetPeerConfiguration("masterserver");
config.SetMessageTypeEnabled(NetIncomingMessageType.UnconnectedData, true);
config.Port = API.MasterServer.MasterServerPort;
peer = new NetPeer(config);
peer.Start();
}
示例3: S_NetworkManager
static S_NetworkManager()
{
NetPeerConfiguration lidServerConfig = new NetPeerConfiguration("chat");
lidServerConfig.Port = 2323;
lidServerConfig.PingInterval = HEARTBEAT_S;
lidServerConfig.ConnectionTimeout = TIMEOUT_S;
lidServerConfig.SetMessageTypeEnabled(NetIncomingMessageType.ConnectionApproval, true);
myLidServer = new NetServer(lidServerConfig);
myLidServer.Start();
}
示例4: Main
static void Main(string[] args)
{
IPEndPoint masterServerEndpoint = NetUtility.Resolve("localhost", CommonConstants.MasterServerPort);
NetPeerConfiguration config = new NetPeerConfiguration("game");
config.SetMessageTypeEnabled(NetIncomingMessageType.NatIntroductionSuccess, true);
config.Port = 14242;
NetServer server = new NetServer(config);
server.Start();
Console.WriteLine("Server started; waiting 5 seconds...");
System.Threading.Thread.Sleep(5000);
var lastRegistered = -60.0f;
while(Console.KeyAvailable == false || Console.ReadKey().Key != ConsoleKey.Escape)
{
// (re-)register periodically with master server
if (NetTime.Now > lastRegistered + 60)
{
// register with master server
NetOutgoingMessage regMsg = server.CreateMessage();
regMsg.Write((byte)MasterServerMessageType.RegisterHost);
IPAddress mask;
IPAddress adr = NetUtility.GetMyAddress(out mask);
regMsg.Write(server.UniqueIdentifier);
regMsg.Write(new IPEndPoint(adr, 14242));
Console.WriteLine("Sending registration to master server");
server.SendUnconnectedMessage(regMsg, masterServerEndpoint);
lastRegistered = (float)NetTime.Now;
}
NetIncomingMessage inc;
while ((inc = server.ReadMessage()) != null)
{
switch (inc.MessageType)
{
case NetIncomingMessageType.VerboseDebugMessage:
case NetIncomingMessageType.DebugMessage:
case NetIncomingMessageType.WarningMessage:
case NetIncomingMessageType.ErrorMessage:
Console.WriteLine(inc.ReadString());
break;
}
}
System.Threading.Thread.Sleep(1);
}
Console.ReadKey();
}
示例5: Run
public static void Run(NetPeer peer)
{
NetPeerConfiguration config = new NetPeerConfiguration("Test");
config.EnableMessageType(NetIncomingMessageType.UnconnectedData);
if (config.IsMessageTypeEnabled(NetIncomingMessageType.UnconnectedData) == false)
throw new NetException("setting enabled message types failed");
config.SetMessageTypeEnabled(NetIncomingMessageType.UnconnectedData, false);
if (config.IsMessageTypeEnabled(NetIncomingMessageType.UnconnectedData) == true)
throw new NetException("setting enabled message types failed");
Console.WriteLine("Misc tests OK");
Console.WriteLine("Hex test: " + NetUtility.ToHexString(new byte[]{0xDE,0xAD,0xBE,0xEF}));
}
示例6: ConnectionManager
static ConnectionManager()
{
config = new NetPeerConfiguration("CWRUShare");
config.AutoFlushSendQueue = true;
config.EnableMessageType(NetIncomingMessageType.DiscoveryRequest);
config.EnableMessageType(NetIncomingMessageType.DiscoveryResponse);
config.EnableMessageType(NetIncomingMessageType.Data);
config.SetMessageTypeEnabled(NetIncomingMessageType.UnconnectedData, true);
currentListView = new FileList();
isListUpdated = false;
config.Port = 14242;
isConnected = false;
server = new NetServer(config);
server.Start();
}
示例7: send
public void send()
{
Patient PAT = new Patient(name.text, family.text, suffix.text, Convert.ToInt32(gender.text), Convert.ToDateTime(birthDate.text), polis.text, Convert.ToInt32(SocialStatus.text), Convert.ToInt32(Privileges.text));
string json = JsonConvert.SerializeObject(PAT);
int ClientPort = 25000;
string ClientIP = "95.31.16.180";
NetPeerConfiguration config = new NetPeerConfiguration(" ");
config.SetMessageTypeEnabled(NetIncomingMessageType.UnconnectedData, true);
config.Port = 1212;
NetClient client = new NetClient(config);
NetOutgoingMessage msg = client.CreateMessage();
msg.Write((byte)0);
msg.Write(json);
client.Start();
client.SendUnconnectedMessage(msg, ClientIP, ClientPort);
Debug.Log("ОК");
}
示例8: Start
void Start()
{
try
{
Debug.Log("client try Start");
config = new NetPeerConfiguration(" ");
DontDestroyOnLoad(this);
config.SetMessageTypeEnabled(NetIncomingMessageType.UnconnectedData, true);
config.Port = 1212;
client = new NetClient(config);
client.Start();
Debug.Log("client Start");
}
catch (Exception e )
{
Debug.Log (e.Message);
}
}
示例9: Main
static void Main(string[] args)
{
Console.WriteLine("Server Started");
Dictionary<IPEndPoint, AvailableGame> registeredHosts = new Dictionary<IPEndPoint, AvailableGame>();
NetPeerConfiguration config = new NetPeerConfiguration("masterserver");
config.SetMessageTypeEnabled(NetIncomingMessageType.UnconnectedData, true);
config.Port = 6000;
NetPeer peer = new NetPeer(config);
peer.Start();
// keep going until ESCAPE is pressed
Console.WriteLine("Press ESC to quit");
while (!Console.KeyAvailable || Console.ReadKey().Key != ConsoleKey.Escape)
{
System.Threading.Thread.Sleep(10);
NetIncomingMessage msg;
while ((msg = peer.ReadMessage()) != null)
{
switch (msg.MessageType)
{
case NetIncomingMessageType.UnconnectedData:
//
// We've received a message from a client or a host
//
// by design, the first byte always indicates action
switch (msg.ReadByte())
{
case 0: // register a new game
// currently only one game per host per router.
if (!registeredHosts.ContainsKey(msg.SenderEndpoint))
{
AvailableGame game = new AvailableGame();
game.Count = msg.ReadInt32();
game.GamerTag = msg.ReadString();
game.PrivateGamerSlots = msg.ReadInt32();
game.MaxGamers = msg.ReadInt32();
game.IsHost = msg.ReadBoolean();
game.InternalIP = msg.ReadIPEndpoint();
game.ExternalIP = msg.SenderEndpoint;
game.Game = msg.ReadString();
Console.WriteLine("Got registration for host " + game.ToString());
registeredHosts.Add(game.ExternalIP, game);
}
break;
case 1:
// It's a client wanting a list of registered hosts
Console.WriteLine("Sending list of " + registeredHosts.Count + " hosts to client " + msg.SenderEndpoint);
string appid = msg.ReadString();
foreach (AvailableGame g1 in registeredHosts.Values)
{
if (g1.Game == appid)
{
// send registered host to client
NetOutgoingMessage om = peer.CreateMessage();
om.Write(g1.Count);
om.Write(g1.GamerTag);
om.Write(g1.PrivateGamerSlots);
om.Write(g1.MaxGamers);
om.Write(g1.IsHost);
om.Write(g1.InternalIP);
om.Write(g1.ExternalIP);
peer.SendUnconnectedMessage(om, msg.SenderEndpoint);
}
}
break;
case 2:
// It's a client wanting to connect to a specific (external) host
IPEndPoint clientInternal = msg.ReadIPEndpoint();
IPEndPoint hostExternal = msg.ReadIPEndpoint();
string token = msg.ReadString();
Console.WriteLine(msg.SenderEndpoint + " requesting introduction to " + hostExternal + " (token " + token + ")");
// find in list
foreach (AvailableGame elist in registeredHosts.Values)
{
if (elist.ExternalIP.Equals(hostExternal))
{
// found in list - introduce client and host to eachother
Console.WriteLine("Sending introduction...");
peer.Introduce(
elist.InternalIP, // host internal
elist.ExternalIP, // host external
clientInternal, // client internal
msg.SenderEndpoint, // client external
token // request token
);
break;
}
}
break;
case 3:
//.........这里部分代码省略.........
示例10: Main
static void Main(string[] args)
{
IPEndPoint masterServerEndpoint = NetUtility.Resolve("localhost", CommonConstants.MasterServerPort);
NetPeerConfiguration config = new NetPeerConfiguration("game");
config.SetMessageTypeEnabled(NetIncomingMessageType.NatIntroductionSuccess, true);
config.Port = 14242;
NetServer server = new NetServer(config);
server.Start();
Console.WriteLine("Server started; waiting 5 seconds...");
System.Threading.Thread.Sleep(5000);
var lastRegistered = -60.0f;
while(Console.KeyAvailable == false || Console.ReadKey().Key != ConsoleKey.Escape)
{
// (re-)register periodically with master server
if (NetTime.Now > lastRegistered + 60)
{
// register with master server
NetOutgoingMessage regMsg = server.CreateMessage();
regMsg.Write((byte)MasterServerMessageType.RegisterHost);
IPAddress mask;
IPAddress adr = NetUtility.GetMyAddress(out mask);
regMsg.Write(server.UniqueIdentifier);
regMsg.Write(new IPEndPoint(adr, 14242));
Console.WriteLine("Sending registration to master server");
server.SendUnconnectedMessage(regMsg, masterServerEndpoint);
lastRegistered = (float)NetTime.Now;
}
NetIncomingMessage inc;
while ((inc = server.ReadMessage()) != null)
{
switch (inc.MessageType)
{
case NetIncomingMessageType.VerboseDebugMessage:
case NetIncomingMessageType.DebugMessage:
case NetIncomingMessageType.WarningMessage:
case NetIncomingMessageType.ErrorMessage:
Console.WriteLine(inc.ReadString());
break;
case NetIncomingMessageType.Data:
// incoming chat message from a client
string chat = inc.ReadString();
Console.WriteLine(chat);
//Output("Broadcasting '" + chat + "'");
// broadcast this to all connections, except sender
List<NetConnection> all = server.Connections; // get copy
all.Remove(inc.SenderConnection);
if (all.Count > 0) {
NetOutgoingMessage om = server.CreateMessage();
om.Write(NetUtility.ToHexString(inc.SenderConnection.RemoteUniqueIdentifier) + " said: " + chat);
server.SendMessage(om, all, NetDeliveryMethod.ReliableOrdered, 0);
}
break;
}
}
System.Threading.Thread.Sleep(1);
}
Console.ReadKey();
}
示例11: InitializeServer
/// <summary>
/// Set up the server, bind to a socket. Use Start to fully start the server after running this
/// </summary>
/// <param name="configuration"></param>
public static void InitializeServer(ServerConfiguration configuration)
{
Configuration = configuration;
if (peer != null && peer.Status != NetPeerStatus.NotRunning)
{
Debug.LogError("cannot start server while already running");
return;
}
_netPeerConfiguration = new NetPeerConfiguration(Configuration.AppIdentifier);
_netPeerConfiguration.Port = Configuration.ListenPort;
_netPeerConfiguration.MaximumConnections = Configuration.MaximumConnections;
connections = new IntDictionary<NetConnection>(Configuration.MaximumConnections);
_netPeerConfiguration.SetMessageTypeEnabled(NetIncomingMessageType.ConnectionApproval, true);
peer = new NetServer(_netPeerConfiguration);
peer.Start();
var serverId = connections.Add(null);
var serverPlayer = new Player();
serverPlayer.Id = (ushort)serverId;
Player.Server = serverPlayer;
GameState.update += Update;
}
示例12: ClientServerStart
static void ClientServerStart()
{
NetPeerConfiguration config = new NetPeerConfiguration(" ");
config.Port = ClientPort;
config.LocalAddress = IPAddress.Parse(ClientIP);
config.MaximumConnections = 10000;
config.SetMessageTypeEnabled(NetIncomingMessageType.UnconnectedData, true);
MediatorServer = new NetServer(config);
MediatorServer.Start();
}
示例13: Main
static void Main(string[] args)
{
Dictionary<long, ServerData> registeredHosts = new Dictionary<long, ServerData>();
NetPeerConfiguration config = new NetPeerConfiguration("masterserver");
config.SetMessageTypeEnabled(NetIncomingMessageType.UnconnectedData, true);
config.Port = SharedConfiguration.MasterServerEndPoint.Port;
NetPeer peer = new NetPeer(config);
peer.Start();
// keep going until ESCAPE is pressed
Console.WriteLine("Press ESC to quit");
while (!Console.KeyAvailable || Console.ReadKey().Key != ConsoleKey.Escape) {
NetIncomingMessage msg;
while ((msg = peer.ReadMessage()) != null) {
switch (msg.MessageType) {
case NetIncomingMessageType.UnconnectedData:
//
// We've received a message from a client or a host
//
// by design, the first byte always indicates action
switch ((MasterServerMessageType)msg.ReadByte()) {
case MasterServerMessageType.RegisterHost:
// It's a host wanting to register its presence
var id = msg.ReadInt64(); // server unique identifier
Console.WriteLine("Got registration for host " + id);
ServerData serverData = new ServerData();
serverData.IPEndPoint[0] = msg.ReadIPEndPoint();
serverData.IPEndPoint[1] = msg.SenderEndPoint;
serverData.ServerName = msg.ReadString();
serverData.ScriptName = msg.ReadString();
serverData.Players = msg.ReadInt32();
serverData.MaxPlayers = msg.ReadInt32();
registeredHosts[id] = serverData;
break;
case MasterServerMessageType.RequestHostList:
// It's a client wanting a list of registered hosts
Console.WriteLine("Sending list of " + registeredHosts.Count + " hosts to client " + msg.SenderEndPoint);
foreach (var kvp in registeredHosts) {
// send registered host to client
NetOutgoingMessage om = peer.CreateMessage();
om.Write(kvp.Key);
om.Write(kvp.Value.IPEndPoint[0]);
om.Write(kvp.Value.IPEndPoint[1]);
om.Write(kvp.Value.ServerName);
om.Write(kvp.Value.ScriptName);
om.Write(kvp.Value.Players);
om.Write(kvp.Value.MaxPlayers);
peer.SendUnconnectedMessage(om, msg.SenderEndPoint);
}
break;
}
break;
case NetIncomingMessageType.DebugMessage:
case NetIncomingMessageType.VerboseDebugMessage:
case NetIncomingMessageType.WarningMessage:
case NetIncomingMessageType.ErrorMessage:
// print diagnostics message
Console.WriteLine(msg.ReadString());
break;
}
}
}
peer.Shutdown("shutting down");
}
示例14: Start
public override void Start()
{
this.backgroundSprite = "MenuPanel";
this.color = new Color32(50, 50, 50, 255);
this.width = 350;
this.height = 185;
this.isVisible = false;
this.position += new Vector3(-this.width/2, this.height/2 + 50);
UILabel ipLabel = this.AddUIComponent<UILabel>();
ipLabel.text = "IP:";
ipLabel.pivot = UIPivotPoint.BottomRight;
ipLabel.relativePosition = new Vector2(10, 10);
m_ipTextField = CreateTextField();
m_ipTextField.width = 140;
m_ipTextField.text = "127.0.0.1";
m_ipTextField.pivot = UIPivotPoint.BottomRight;
m_ipTextField.relativePosition = new Vector2(55, 10);
UILabel portLabel = this.AddUIComponent<UILabel>();
portLabel.text = "Port:";
portLabel.pivot = UIPivotPoint.BottomRight;
portLabel.relativePosition = new Vector2(10, 45);
m_portTextField = CreateTextField();
m_portTextField.numericalOnly = true;
m_portTextField.text = "27015";
m_portTextField.pivot = UIPivotPoint.BottomRight;
m_portTextField.relativePosition = new Vector2(55, 45);
UIButton connectButton = CreateButton();
connectButton.text = "CONNECT";
connectButton.width = 100;
connectButton.height = 60;
connectButton.pivot = UIPivotPoint.BottomRight;
connectButton.relativePosition = new Vector2(this.width - connectButton.width - 110, this.height - connectButton.height - 5);
connectButton.eventClick += OnClickConnect;
UIButton closeButton = CreateButton();
closeButton.text = "CANCEL";
closeButton.width = 100;
closeButton.height = 60;
closeButton.pivot = UIPivotPoint.BottomRight;
closeButton.relativePosition = new Vector2(this.width - closeButton.width - 5, this.height - closeButton.height - 5);
closeButton.eventClick += OnClickCancel;
m_connectionInfoLabel = this.AddUIComponent<UILabel>();
m_connectionInfoLabel.text = "";
m_connectionInfoLabel.pivot = UIPivotPoint.TopLeft;
m_connectionInfoLabel.relativePosition = new Vector2(10, 80);
m_connectionInfoLabel.textAlignment = UIHorizontalAlignment.Left;
NetPeerConfiguration config = new NetPeerConfiguration("FPSMod");
config.SetMessageTypeEnabled(NetIncomingMessageType.UnconnectedData, true);
m_netClient = new NetClient(config);
m_netClient.Start();
}
示例15: S_LidgrenContainer
/// <summary>
/// Initialize the Lidgren NetServer.
/// </summary>
public S_LidgrenContainer(ServerWindow setServerWindow) //Need to know an instance of ChatWindow so we can pass commands along to it in HandleCustomMessages.
{
NetPeerConfiguration lidServerConfig = new NetPeerConfiguration("chat");
lidServerConfig.Port = 2323;
lidServerConfig.PingInterval = HEARTBEAT_S;
lidServerConfig.ConnectionTimeout = TIMEOUT_S;
lidServerConfig.SetMessageTypeEnabled(NetIncomingMessageType.ConnectionApproval, true);
myLidServer = new NetServer(lidServerConfig);
myLidServer.Start();
}