本文整理汇总了C#中Lidgren.Network.NetClient.Start方法的典型用法代码示例。如果您正苦于以下问题:C# NetClient.Start方法的具体用法?C# NetClient.Start怎么用?C# NetClient.Start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lidgren.Network.NetClient
的用法示例。
在下文中一共展示了NetClient.Start方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MasterServer
/// <summary>
/// Server constructor, starts the server and connects to all region servers.
/// </summary>
/// <remarks>
/// TODO: Make the config file be able to be in a different location. Load from command line.
/// </remarks>
public MasterServer()
{
//Load this region server's junk from xml
XmlSerializer deserializer = new XmlSerializer(typeof(MasterConfig));
MasterConfig masterconfig = (MasterConfig)deserializer.Deserialize(XmlReader.Create(@"C:\Users\Addie\Programming\Mobius\Mobius.Server.MasterServer\bin\Release\MasterData.xml"));
//Start it with the name MobiusMasterServer, and let connection approvals be enabled
var config = new NetPeerConfiguration(masterconfig.ServerName);
config.Port = masterconfig.ServerPort;
config.MaximumConnections = masterconfig.MaxConnections;
config.EnableMessageType(NetIncomingMessageType.ConnectionApproval);
LidgrenServer = new NetServer(config);
RegionServers = new Dictionary<ushort, NetClient>();
foreach(RegionInfo info in masterconfig.RegionServers)
{
NetClient region = new NetClient(new NetPeerConfiguration(info.ServerName));
region.Start();
region.Connect(info.ServerIp, info.ServerPort);
RegionServers.Add(info.RegionId, region);
}
//Initialize our data structures
Users = new Dictionary<Guid, User>();
UserIdToCharacters = new Dictionary<Guid, List<Character>>();
//Start the server
LidgrenServer.Start();
}
示例2: SetupClient
private void SetupClient()
{
NetPeerConfiguration config = new NetPeerConfiguration("dystopia");
Client = new NetClient(config);
Client.Start();
Client.Connect(NetUtility.Resolve(ServerIP, ServerPort));
}
示例3: NetworkClient
public NetworkClient(string Host, int Port)
{
Config = new NetPeerConfiguration("GameServer01");
ClientConnection = new NetClient(Config);
ClientConnection.Start();
ClientConnection.Connect(Host, Port);
}
示例4: SetUpConnection
public void SetUpConnection()
{
configuration = new NetPeerConfiguration("PingPong");
configuration.EnableMessageType(NetIncomingMessageType.WarningMessage);
configuration.EnableMessageType(NetIncomingMessageType.VerboseDebugMessage);
configuration.EnableMessageType(NetIncomingMessageType.ErrorMessage);
configuration.EnableMessageType(NetIncomingMessageType.Error);
configuration.EnableMessageType(NetIncomingMessageType.DebugMessage);
configuration.EnableMessageType(NetIncomingMessageType.ConnectionApproval);
configuration.EnableMessageType(NetIncomingMessageType.Data);
switch (networkRole)
{
case GamerNetworkType.Client:
Client = new NetClient(configuration);
Client.Start();
Client.Connect(new IPEndPoint(NetUtility.Resolve(IP), Convert.ToInt32(Port)));
break;
case GamerNetworkType.Server:
configuration.Port = Convert.ToInt32(Port);
Server = new NetServer(configuration);
Server.Start();
break;
default:
throw new ArgumentException("Network type was not set");
}
}
示例5: ConfigMultiplayerScreen
/// <summary>
/// Constructor
/// </summary>
public ConfigMultiplayerScreen()
: base("Multiplayer options")
{
// Create Menu Entries
figureMenuEntry = new MenuEntry(string.Empty);
serverMenuEntry = new MenuEntry("Connect To Server");
var start = new MenuEntry("Start game");
var back = new MenuEntry("Back");
// Hook up menue event handlers
figureMenuEntry.Selected += figureMenuSelected;
serverMenuEntry.Selected += serverMenuSelected;
start.Selected += StartGame;
back.Selected += OnCancel;
// Add Entries to Menu
MenuEntries.Add(serverMenuEntry);
MenuEntries.Add(figureMenuEntry);
MenuEntries.Add(start);
MenuEntries.Add(back);
//Initialize();
//initialize networkManager
//configure client
client = new NetClient(new NetPeerConfiguration("pacman"));
//Start client
client.Start();
networkManager = new ClientNetworkManager(client);
}
示例6: Connect
public void Connect()
{
client = new NetClient(config);
client.Start();
client.DiscoverLocalPeers(14242);
}
示例7: 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();
Console.WriteLine("IP to connect to: ");
String ip = Console.ReadLine();
client.Connect("192.168.1.2", 80);
while (true)
{
if (client.ServerConnection != null)
{
string msg = Console.ReadLine();
NetOutgoingMessage sendMsg = client.CreateMessage();
sendMsg.Write(msg);
client.SendMessage(sendMsg, NetDeliveryMethod.ReliableOrdered);
}
}
}
示例8: WorldClientBase
public WorldClientBase(string protocolVersion)
{
this.protocolVersion = protocolVersion;
// Net configuration
NetPeerConfiguration cfg = new NetPeerConfiguration("Asteria");
cfg.MaximumConnections = 1;
cfg.ReceiveBufferSize = 4095;
cfg.MaximumTransmissionUnit = 4095;
#if DEBUG
try
{
cfg.EnableMessageType(NetIncomingMessageType.VerboseDebugMessage);
}
catch
{
Logger.Output(this, "Running in debug mode but using release Lidgren library version, Lidgren debug messages disabled!");
}
#endif
client = new NetClient(cfg);
client.Start();
// Create objects needed.
sendingQ = new Queue<ClientToServerMessage>(64);
receivingQ = new Queue<NetIncomingMessage>(128);
newDataArrivedEvent = new AutoResetEvent(false);
messages = new Dictionary<MessageType, List<ServerToClientMessage>>();
serializer = new ClientToServerMessageSerializer();
deserializer = new ServerToClientMessageSerializer();
isRunning = true;
}
示例9: StartClientConnection
public void StartClientConnection(string ip, string port)
{
_config = new NetPeerConfiguration(GameConfiguration.NetworkAppIdentifier)
{
#if DEBUG
//PingInterval = 1f, // send ping every 1 second
//SimulatedLoss = 0.5f, // from 0 to 1
SimulatedMinimumLatency = GameConfiguration.SimulatedMinimumLatency,
#endif
};
_config.EnableMessageType(NetIncomingMessageType.ConnectionLatencyUpdated);
_hasStarted = true;
_connected = false;
_disconnected = false;
// Client initialize
_client = new NetClient(_config);
_client.Start();
_messagePool = new Queue<NetIncomingMessage>();
var threadStart = new ThreadStart(MessagePooling);
_messagePooling = new Thread(threadStart);
_messagePooling.Start();
TryToConnect(ip, port);
}
示例10: NetworkMultiplayer
public NetworkMultiplayer(bool createServer = false)
: base(GameModes.Network)
{
if(createServer)
GameServer = new GameServer();
//read network on each update
Game.Instance.OnUpdate += ReadNetwork;
//server config
NetPeerConfiguration config = new NetPeerConfiguration("tank");
config.EnableMessageType(NetIncomingMessageType.DiscoveryResponse);
//server creation
Client = new NetClient(config);
Client.Start();
if (!createServer)
{
//check whether the user has a known server
ListMenu serverMenu = new ListMenu("Do you want to connect to a given IP (if yes, enter in console)?", "tank.Code.YESORNOCHOOSENOW", ConnectionMethodSelectionCallback);
Scene.Add(serverMenu);
}
else//we know that a local server must exist
Client.DiscoverLocalPeers(14242);
//register handler for receiving data
OnClientData += IncomingHandler;
//are we client, or are we dancer?
if(!createServer)
Console.WriteLine("client");
}
示例11: 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);
}
示例12: InitClients
public void InitClients(int netClientcount)
{
m_NetClientCount = netClientcount;
Nets = new NetClient[m_NetClientCount];
TextNetMsgS = new string[m_NetClientCount];
m_lastSent = new double[m_NetClientCount];
TextNetMsgSB = new StringBuilder();
System.Net.IPAddress mask = null;
System.Net.IPAddress local = NetUtility.GetMyAddress(out mask);
//
for (int i = 0; i < Nets.Length; i++) {
NetPeerConfiguration config = new NetPeerConfiguration("many");
config.LocalAddress = local;
#if DEBUG
config.SimulatedLoss = 0.02f;
#endif
NetClient Net = new NetClient(config);
Nets[i] = Net;
Net.Start();
//Net.Connect("localhost", 14242);
Net.Connect(new System.Net.IPEndPoint(config.LocalAddress, 14242));
//
Application.DoEvents();
}
}
示例13: StartDiscoveryInternal
/// <summary>
///
/// </summary>
/// <param name="numPorts"></param>
/// <param name="timeout"></param>
void StartDiscoveryInternal ( int numPorts, TimeSpan timeout )
{
lock (lockObj) {
if (client!=null) {
Log.Warning("Discovery is already started.");
return;
}
this.timeout = timeout;
var netConfig = new NetPeerConfiguration( Game.GameID );
netConfig.EnableMessageType( NetIncomingMessageType.DiscoveryRequest );
netConfig.EnableMessageType( NetIncomingMessageType.DiscoveryResponse );
client = new NetClient( netConfig );
client.Start();
var svPort = Game.Network.Port;
var ports = Enumerable.Range(svPort, numPorts)
.Where( p => p <= ushort.MaxValue )
.ToArray();
Log.Message("Start discovery on ports: {0}", string.Join(", ", ports) );
foreach (var port in ports) {
client.DiscoverLocalPeers( port );
}
}
}
示例14: NetClientHelper
public NetClientHelper()
{
NetPeerConfiguration config = new NetPeerConfiguration("CozyKxlol");
config.EnableMessageType(NetIncomingMessageType.DiscoveryResponse);
client = new NetClient(config);
client.Start();
}
示例15: RemoteServerImpl
private RemoteServerImpl(Peer peer)
{
Peer = peer;
Peer.Start();
_writerStream = new MemoryStream();
_readerStream = new MemoryStream();
}