本文整理汇总了C#中Net.Connect方法的典型用法代码示例。如果您正苦于以下问题:C# Net.Connect方法的具体用法?C# Net.Connect怎么用?C# Net.Connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Net
的用法示例。
在下文中一共展示了Net.Connect方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
Net net = new Net();
net.Connect();
while(true) {
Tuple<NetEventType, Object> evt = net.PollNetworkEvent();
if(evt != null) {
Console.WriteLine(evt.GetFirst());
switch(evt.GetFirst()) {
case NetEventType.CONNECT:
net.Write("ping\n");
break;
case NetEventType.DATA_READ:
Console.Write(evt.GetSecond());
net.Write("pong\n");
break;
case NetEventType.DISCONNECT:
Environment.Exit(0);
break;
}
}
}
}
示例2: Main
static void Main(string[] args)
{
mNet = new Net();
mNet.ConnectionClosed += mNet_ConnectionClosed;
mAudioOut = new AudioOut(mNet.AudioOutStream);
mAudioIn = new AudioIn_KinectXbox(mNet.AudioInStream);
string server = "127.0.0.1";
int port = 31337;
bool retryConnects = true;
//parse arguments
//setup
while (true)
{
//connect to server
if (!mNet.Connected)
{
if (!mNet.Connect(server, port))
{
Console.Write("Err: failed to connect.");
if (retryConnects)
{
Console.WriteLine(" Waiting 5s and then will retry");
Thread.Sleep(5000);
continue;
}
else
{
break;
}
}
}
//enter message loop
Net.EMSG_TYPE msg = mNet.Recv(true); //note this may still block for a short time
switch (msg)
{
case Net.EMSG_TYPE.CONFIG:
Console.WriteLine("Received config, sending ready");
mNet.Send(Net.EMSG_TYPE.READY);
break;
case Net.EMSG_TYPE.START:
Console.WriteLine("Received start");
mAudioIn.Start();
break;
case Net.EMSG_TYPE.STOP:
Console.WriteLine("Received stop");
mAudioIn.Stop();
break;
case Net.EMSG_TYPE.GETBASE:
Console.WriteLine("Received baseline request");
mNet.Send(Net.EMSG_TYPE.BASELINE);
break;
case Net.EMSG_TYPE.AUDIOOUT:
//mAudioOut.DataReceived();
break;
default:
break;
}
//Thread.Sleep(50); //ms
}
}