本文整理汇总了C#中Lidgren.Network.NetClient.RegisterReceivedCallback方法的典型用法代码示例。如果您正苦于以下问题:C# NetClient.RegisterReceivedCallback方法的具体用法?C# NetClient.RegisterReceivedCallback怎么用?C# NetClient.RegisterReceivedCallback使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lidgren.Network.NetClient
的用法示例。
在下文中一共展示了NetClient.RegisterReceivedCallback方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Init
public void Init(string app_identifier, bool auth_flush_send_queue, bool use_multi_thread)
{
this.app_identifier = app_identifier;
NetPeerConfiguration config = new NetPeerConfiguration(this.app_identifier);
config.AutoFlushSendQueue = auth_flush_send_queue;
net_client = new NetClient(config);
if (SynchronizationContext.Current == null)
{
SynchronizationContext.SetSynchronizationContext(new STASynchronizationContext());
}
if (use_multi_thread == false && SynchronizationContext.Current != null)
{
net_client.RegisterReceivedCallback(new SendOrPostCallback(GotMessage));
}
else
{
net_worker = new BackgroundWorker();
net_worker.DoWork += new DoWorkEventHandler(net_worker_DoWork);
net_worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(net_worker_RunWorkerCompleted);
}
}
示例2: Client
public Client()
{
NetPeerConfiguration config = new NetPeerConfiguration("CozyAnywhere");
config.EnableMessageType(NetIncomingMessageType.DiscoveryResponse);
client = new NetClient(config);
client.RegisterReceivedCallback(RecivePacket);
}
示例3: ConnectServer
private static NetClient ConnectServer()
{
var config = new NetPeerConfiguration("pic") {EnableUPnP = true};
var thisClient = new NetClient(config);
thisClient.RegisterReceivedCallback(HandleMessage);
return thisClient;
}
示例4: 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);
}
示例5: CozyClient
public CozyClient(string ClientName)
{
NetPeerConfiguration config = new NetPeerConfiguration(ClientName);
config.EnableMessageType(NetIncomingMessageType.DiscoveryResponse);
InnerClient = new NetClient(config);
InnerClient.RegisterReceivedCallback(RecivePacket);
}
示例6: 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);
}
}
示例7: button1_Click
private void button1_Click(object sender, EventArgs e)
{
var config = new NetPeerConfiguration("Chat_lobby");
client = new NetClient(config);
client.RegisterReceivedCallback(new SendOrPostCallback(GotMessage));
client.Start();
client.Connect("localhost", 12345);
}
示例8: Init
public override void Init()
{
NetPeerConfiguration config = new NetPeerConfiguration("chat");
config.AutoFlushSendQueue = false;
s_client = new NetClient(config);
s_client.RegisterReceivedCallback(new SendOrPostCallback(GotMessage));
}
示例9: Client
public Client()
{
NetPeerConfiguration config = new NetPeerConfiguration("ths");
config.AutoFlushSendQueue = false;
_client = new NetClient(config);
_client.RegisterReceivedCallback(new SendOrPostCallback(GotMessage));
InitializeInteractionActionsTable();
InitializeOutboxActionTable();
NetworkStatus = NetworkStatusEnum.Disconnected;
}
示例10: start
public static void start()
{
net = new NetClient(config);
net.RegisterReceivedCallback(new SendOrPostCallback((e) =>
{
message = net.ReadMessage();
messageRecieved(message);
}), new SynchronizationContext());
print("info", "Starting...");
net.Start();
print("info", "Client Running");
}
示例11: 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);
}
示例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: 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));
}
}
示例15: Main
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
s_form = new Form1();
NetPeerConfiguration config = new NetPeerConfiguration("chat");
config.AutoFlushSendQueue = false;
s_client = new NetClient(config);
s_client.RegisterReceivedCallback(new SendOrPostCallback(GotMessage));
Application.Run(s_form);
s_client.Shutdown("Bye");
}