You've already forked lidgren-network-gen3
mirror of
https://github.com/lidgren/lidgren-network-gen3.git
synced 2026-05-06 02:11:06 +09:00
Tweaked/fixed some samples
This commit is contained in:
@@ -17,6 +17,8 @@ namespace ImageClient
|
||||
public bool[] ReceivedSegments;
|
||||
public int NumReceivedSegments;
|
||||
|
||||
private double m_startedFetching;
|
||||
|
||||
public ImageGetter(string host, NetPeerConfiguration copyConfig)
|
||||
{
|
||||
InitializeComponent();
|
||||
@@ -27,7 +29,23 @@ namespace ImageClient
|
||||
Client = new NetClient(config);
|
||||
Client.Start();
|
||||
|
||||
Client.DiscoverLocalPeers(14242);
|
||||
if (!string.IsNullOrEmpty(host))
|
||||
{
|
||||
Client.Connect(host, 14242, GetApproveData());
|
||||
}
|
||||
else
|
||||
{
|
||||
Client.DiscoverLocalPeers(14242);
|
||||
}
|
||||
}
|
||||
|
||||
private NetOutgoingMessage GetApproveData()
|
||||
{
|
||||
// create approval data
|
||||
NetOutgoingMessage approval = Client.CreateMessage();
|
||||
approval.Write(42);
|
||||
approval.Write("secret");
|
||||
return approval;
|
||||
}
|
||||
|
||||
public void Heartbeat()
|
||||
@@ -39,15 +57,8 @@ namespace ImageClient
|
||||
{
|
||||
case NetIncomingMessageType.DiscoveryResponse:
|
||||
// found server! just connect...
|
||||
|
||||
string serverResponseHello = inc.ReadString();
|
||||
|
||||
// create approval data
|
||||
NetOutgoingMessage approval = Client.CreateMessage();
|
||||
approval.Write(42);
|
||||
approval.Write("secret");
|
||||
|
||||
Client.Connect(inc.SenderEndpoint, approval);
|
||||
Client.Connect(inc.SenderEndpoint, GetApproveData());
|
||||
break;
|
||||
case NetIncomingMessageType.DebugMessage:
|
||||
case NetIncomingMessageType.VerboseDebugMessage:
|
||||
@@ -55,12 +66,14 @@ namespace ImageClient
|
||||
case NetIncomingMessageType.ErrorMessage:
|
||||
string str = inc.ReadString();
|
||||
NativeMethods.AppendText(richTextBox1, str);
|
||||
System.IO.File.AppendAllText("C:\\tmp\\clientlog.txt", str + Environment.NewLine);
|
||||
//System.IO.File.AppendAllText("C:\\tmp\\clientlog.txt", str + Environment.NewLine);
|
||||
break;
|
||||
case NetIncomingMessageType.StatusChanged:
|
||||
NetConnectionStatus status = (NetConnectionStatus)inc.ReadByte();
|
||||
string reason = inc.ReadString();
|
||||
NativeMethods.AppendText(richTextBox1, "New status: " + status + " (" + reason + ")");
|
||||
if (status == NetConnectionStatus.Connected)
|
||||
m_startedFetching = NetTime.Now;
|
||||
break;
|
||||
case NetIncomingMessageType.Data:
|
||||
// image data, whee!
|
||||
@@ -140,6 +153,10 @@ namespace ImageClient
|
||||
}
|
||||
}
|
||||
|
||||
double span = NetTime.Now - m_startedFetching;
|
||||
double bytesPerSecond = (double)totalBytes / span;
|
||||
NativeMethods.AppendText(richTextBox1, "Fetched at " + NetUtility.ToHumanReadable((long)bytesPerSecond) + " per second");
|
||||
|
||||
Client.Disconnect("So long and thanks for all the fish!");
|
||||
}
|
||||
|
||||
|
||||
@@ -19,8 +19,15 @@ namespace ImageClient
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
MainForm = new Form1();
|
||||
|
||||
Application.Idle += new EventHandler(AppLoop);
|
||||
Application.Run(MainForm);
|
||||
try
|
||||
{
|
||||
Application.Idle += new EventHandler(AppLoop);
|
||||
Application.Run(MainForm);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
MessageBox.Show("Ouch: " + ex);
|
||||
}
|
||||
}
|
||||
|
||||
static void AppLoop(object sender, EventArgs e)
|
||||
|
||||
@@ -26,6 +26,7 @@ namespace ImageServer
|
||||
NetPeerConfiguration config = new NetPeerConfiguration("ImageTransfer");
|
||||
config.EnableMessageType(NetIncomingMessageType.ConnectionApproval);
|
||||
config.EnableMessageType(NetIncomingMessageType.DiscoveryRequest);
|
||||
config.AutoExpandMTU = true;
|
||||
|
||||
// listen on port 14242
|
||||
config.Port = 14242;
|
||||
@@ -57,7 +58,7 @@ namespace ImageServer
|
||||
// just print any message
|
||||
string str = inc.ReadString();
|
||||
NativeMethods.AppendText(MainForm.richTextBox1, str);
|
||||
System.IO.File.AppendAllText("C:\\tmp\\serverlog.txt", str + Environment.NewLine);
|
||||
//System.IO.File.AppendAllText("C:\\tmp\\serverlog.txt", str + Environment.NewLine);
|
||||
break;
|
||||
case NetIncomingMessageType.DiscoveryRequest:
|
||||
NetOutgoingMessage dom = Server.CreateMessage();
|
||||
|
||||
@@ -77,7 +77,7 @@ namespace SpeedTestServer
|
||||
break;
|
||||
case NetDeliveryMethod.UnreliableSequenced:
|
||||
case NetDeliveryMethod.ReliableSequenced:
|
||||
if (expected < nr)
|
||||
if (nr < expected)
|
||||
throw new NetException(im.DeliveryMethod.ToString() + " failed! Expected " + expected + " received " + nr);
|
||||
s_nextNumber[slot] = nr + 1;
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user