本文整理汇总了C#中Lidgren.Network.NetClient.CreateMessage方法的典型用法代码示例。如果您正苦于以下问题:C# NetClient.CreateMessage方法的具体用法?C# NetClient.CreateMessage怎么用?C# NetClient.CreateMessage使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lidgren.Network.NetClient
的用法示例。
在下文中一共展示了NetClient.CreateMessage方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: sendRequest
public void sendRequest(NetClient n, int id, byte property)
{
NetOutgoingMessage propertyMessage = n.CreateMessage();
propertyMessage.Write(id);
NetOutgoingMessage idMessage = n.CreateMessage();
idMessage.Write(property);
n.SendMessage(idMessage, NetDeliveryMethod.ReliableOrdered);
n.SendMessage(propertyMessage, NetDeliveryMethod.ReliableOrdered);
}
示例2: connectToServer
public NetClient connectToServer(string ip, int port, string appname, int playernr, int entityID)
{
NetPeerConfiguration npc = new NetPeerConfiguration(appname);
NetClient n = new NetClient(npc);
n.Connect(ip, port);
Debug.Log("Connected succesfully!");
NetOutgoingMessage mess = n.CreateMessage();
mess.Write(playernr);
NetOutgoingMessage nm = n.CreateMessage();
nm.Write(entityID);
n.SendMessage(mess, NetDeliveryMethod.ReliableOrdered);
n.SendMessage(nm, NetDeliveryMethod.ReliableOrdered);
Debug.Log("Cleared identity with server!");
return n;
}
示例3: Connect
public static void Connect(IPEndPoint endpoint, MMDevice device, ICodec codec)
{
var config = new NetPeerConfiguration("airgap");
_client = new NetClient(config);
_client.RegisterReceivedCallback(MessageReceived);
_client.Start();
_waveIn = new WasapiLoopbackCapture(device);
_codec = codec;
_sourceFormat = _waveIn.WaveFormat;
_targetFormat = new WaveFormat(_codec.SampleRate, _codec.Channels); // format to convert to
_waveIn.DataAvailable += SendData;
_waveIn.RecordingStopped += (sender, args) => Console.WriteLine("Stopped");
// TODO: RecordingStopped is called when you change the audio device settings, should recover from that
NetOutgoingMessage formatMsg = _client.CreateMessage();
formatMsg.Write(_targetFormat.Channels);
formatMsg.Write(_targetFormat.SampleRate);
formatMsg.Write(codec.Name);
_client.Connect(endpoint, formatMsg);
}
示例4: Main
public static void Main(string[] args)
{
Console.WriteLine("[CLIENT] Testing Lidgren-Network-v3...");
NetPeerConfiguration clientConfig = new NetPeerConfiguration("test");
clientConfig.EnableMessageType(NetIncomingMessageType.DiscoveryResponse);
NetClient client = new NetClient(clientConfig);
client.Start();
SynchronizationContext.SetSynchronizationContext(new SynchronizationContext());
client.RegisterReceivedCallback(new SendOrPostCallback(GotMessage));
Console.WriteLine("IP to connect to: ");
String ip = Console.ReadLine();
client.Connect(new System.Net.IPEndPoint(System.Net.IPAddress.Parse(ip), 12345));
while(true) {
string msg = Console.ReadLine();
NetOutgoingMessage sendMsg = client.CreateMessage();
sendMsg.Write("[CLIENT] " + msg);
client.SendMessage(sendMsg, NetDeliveryMethod.ReliableOrdered);
}
}
示例5: SendUpdates
public void SendUpdates(NetClient client)
{
NetOutgoingMessage om = client.CreateMessage();
om.Write(Helpers.TransferType.ProjectileUpdate);
om.Write(new ProjectileTransferableData(client.UniqueIdentifier,ID,IsValid,Position,Angle));
client.SendMessage(om, NetDeliveryMethod.UnreliableSequenced);
}
示例6: Initialize
public int Initialize(List<BaseUnit> VecUnits, Map map)
{
config = new NetPeerConfiguration("StarKampf");
client = new NetClient(config);
client.Start();
client.Connect(host: "127.0.0.1", port: 12345);
side = 0; // later somebody need make ini side in moment connecting to the server // later means never // это типа комментарий к комментарию, ну вы поняли да?)
outMsg = client.CreateMessage();
unitsManager = new UnitsManager(VecUnits, map);
return side;
}
示例7: Initialize
public int Initialize(ref List<BaseUnit> VecUnits, Map map)
{
config = new NetPeerConfiguration("StarKampf");
client = new NetClient(config);
client.Start();
client.Connect(host: "127.0.0.1", port: 12345);
outMsg = client.CreateMessage();
this.VecUnits = VecUnits;
unitsManager = new UnitsManager(ref VecUnits, map);
OutComingCommandAboutIni = string.Empty;
return side;
}
示例8: ConnectPlayerToLobby
public static void ConnectPlayerToLobby(string playername, Color playercolor)
{
NetPeerConfiguration config = new NetPeerConfiguration("chat");
config.AutoFlushSendQueue = false;
s_client = new NetClient(config);
s_client.RegisterReceivedCallback(new SendOrPostCallback(LobbyForm.GotMessage));
string hailmessage = guid.ToString() + ";" + playername + ";" + Convert.ToString(playercolor.ToArgb());
s_client.Start();
NetOutgoingMessage hail = s_client.CreateMessage(hailmessage);
s_client.Connect(settings.ServerAdresse, settings.ChatPort, hail);
}
示例9: Start
public bool Start()
{
var random = new Random();
_client = new NetClient(new NetPeerConfiguration("networkGame"));
_client.Start();
Username = "name_" + random.Next(0, 100);
GroupId = "test";
var outmsg = _client.CreateMessage();
outmsg.Write(GroupId);
outmsg.Write((byte)PacketType.Login);
outmsg.Write(Username);
_client.Connect("localhost", 14241, outmsg);
return EsablishInfo();
}
示例10: SetupClient
public void SetupClient(string gameName, string ip = "127.0.0.1", int port = 14242)
{
// Create new client, with previously created configs
var config = new NetPeerConfiguration(gameName);
_listOfOtherPlayers = new List<HeroEntity>();
_client = new NetClient(config);
_client.Start();
// Connect client, to ip previously requested from user
var outmsg = _client.CreateMessage();
outmsg.Write(PacketType.Login);
outmsg.WriteAllProperties(MainGame.MyHero.MyLoginInfo);
_client.Connect(ip, port, outmsg);
}
示例11: Main
static void Main(string[] args)
{
var config = new NetPeerConfiguration("enctest");
var client = new NetClient(config);
client.Start();
System.Threading.Thread.Sleep(100); // give server time to start up
client.Connect("localhost", 14242);
var encryption = new NetAESEncryption(client, "Hallonpalt");
// loop forever
while (true)
{
// read messages
var inc = client.ReadMessage();
if (inc != null)
{
switch (inc.MessageType)
{
case NetIncomingMessageType.DebugMessage:
case NetIncomingMessageType.WarningMessage:
case NetIncomingMessageType.VerboseDebugMessage:
case NetIncomingMessageType.ErrorMessage:
Console.WriteLine(inc.ReadString());
break;
case NetIncomingMessageType.StatusChanged:
var status = (NetConnectionStatus)inc.ReadByte();
Console.WriteLine(inc.SenderConnection + " (" + status + ") " + inc.ReadString());
break;
}
}
// if we're connected, get input and send
if (client.ServerConnection != null && client.ServerConnection.Status == NetConnectionStatus.Connected)
{
Console.WriteLine("Type a message:");
var input = Console.ReadLine();
var msg = client.CreateMessage();
msg.Write(input);
encryption.Encrypt(msg);
var ok = client.SendMessage(msg, NetDeliveryMethod.ReliableOrdered);
Console.WriteLine("Message sent: " + ok);
}
}
}
示例12: ConnectToServer
public static void ConnectToServer()
{
NetPeerConfiguration netconfig = new NetPeerConfiguration("game");
netclient = new NetClient(netconfig);
if (SynchronizationContext.Current == null)
SynchronizationContext.SetSynchronizationContext(new SynchronizationContext());
netclient.RegisterReceivedCallback(new SendOrPostCallback(ReceivedData));
netclient.Start();
NetOutgoingMessage message = netclient.CreateMessage("Connect");
netclient.Connect(settings.ServerAdresse, settings.GamePort, message);
}
示例13: Main
static List<Player> players; //This will hold all players info from server
#endregion Fields
#region Methods
static void Main(string[] args)
{
SynchronizationContext.SetSynchronizationContext(new SynchronizationContext());
players = new List<Player>();
Config = new NetPeerConfiguration("DND Server");//APP ID
Console.WriteLine("Created Client Configuration.");
// Config.Port = _SERVERPORT;
Client = new NetClient(Config);
Console.WriteLine("Initialized client socket");
Client.RegisterReceivedCallback(new SendOrPostCallback(RecieveData));
//Register the recieve callback. Better if its before when the socket starts
Client.Start();//start the socket
Console.WriteLine("started the client socket");
Client.Connect("localhost", _SERVERPORT);//connect the client to the server
Console.WriteLine("Requesting Connection to server");
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
//An example input manager to get respont on console
new Thread(new ThreadStart(delegate
{
string input;
while ((input = Console.ReadLine()) != null)
{
Console.WriteLine("Console input.");
string[] prms = input.Split(' ');//params for the input
switch (prms[0])//The first param is the command name
{
case "/changename":
//TODO: add code later
break;
case "/say":
NetOutgoingMessage outmsg;
outmsg = Client.CreateMessage();
outmsg.Write((byte)Headers.Chat);
string Message = "";
for(int i = 1; i < prms.Length; i++)
Message += prms[i] + " ";
Message += "\n";
outmsg.Write(Message);
Client.SendMessage(outmsg, NetDeliveryMethod.ReliableOrdered);
break;
}
}
})).Start();
//END INPUT MANAGEMENT
}
示例14: Start
public override void Start()
{
if (m_peer != null)
{
throw new InvalidOperationException("Client already running");
}
NetPeerConfiguration config = new NetPeerConfiguration(m_name);
m_peer = new NetClient(config);
m_peer.Start();
NetOutgoingMessage hailMessage = m_peer.CreateMessage();
hailMessage.Write(CVars.name.value);
m_peer.Connect(m_remoteEndPoint, hailMessage);
}
示例15: Start
public bool Start()
{
Client = new NetClient(new NetPeerConfiguration("Battleship438"));
Client.Configuration.EnableMessageType(NetIncomingMessageType.Data);
Client.Configuration.EnableMessageType(NetIncomingMessageType.ConnectionApproval);
Client.Start();
Player = new Library.Player("Kevin F", 20, 10);
//TODO: NEED TO ACQUIRE PLAYER1/2 FROM SERVER
var outMsg = Client.CreateMessage();
outMsg.Write((byte)PacketType.Login);
outMsg.Write(Player.Name);
outMsg.Write(Player.X);
outMsg.Write(Player.Y);
Client.Connect("localhost", 14241, outMsg);
return EstablishInfo();
}