本文整理汇总了C#中Peer.SendData方法的典型用法代码示例。如果您正苦于以下问题:C# Peer.SendData方法的具体用法?C# Peer.SendData怎么用?C# Peer.SendData使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Peer
的用法示例。
在下文中一共展示了Peer.SendData方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SendServerInformation
public void SendServerInformation(Peer destinationPeer)
{
using (System.IO.MemoryStream memStream = new System.IO.MemoryStream())
{
using (System.IO.BinaryWriter writer = new System.IO.BinaryWriter(memStream))
{
writer.Write(CurrentUser);
writer.Write(peers.Count((Peer p) => { return p.isLoggedIn; }) +
peersToAdd.Count((Peer p) => { return p.isLoggedIn; }));
foreach (Peer peer in peers)
{
if (peer.isLoggedIn)
{
writer.Write(peer.Address.Address.ToString());
writer.Write(peer.listenPort);
writer.Write(peer.name);
}
}
foreach (Peer peer in peersToAdd)
{
if (peer.isLoggedIn)
{
writer.Write(peer.Address.Address.ToString());
writer.Write(peer.listenPort);
writer.Write(peer.name);
}
}
destinationPeer.SendData(P2PNotices.ServerGameInformation, memStream.ToArray());
}
}
}
示例2: OnServerInformationReceived
void OnServerInformationReceived(byte[] data)
{
using (System.IO.MemoryStream readStream = new System.IO.MemoryStream(data))
{
using (System.IO.BinaryReader reader = new System.IO.BinaryReader(readStream))
{
ServerPeer.name = reader.ReadString();
int peerCount = reader.ReadInt32();
for (int i = 0; i < peerCount; ++i)
{
string address = reader.ReadString();
int port = reader.ReadInt32();
string username = reader.ReadString();
Peer peer = new Peer(new IPEndPoint(IPAddress.Parse(address), port), true);
peer.name = username;
using (System.IO.MemoryStream writeStream = new System.IO.MemoryStream())
{
using (System.IO.BinaryWriter writer = new System.IO.BinaryWriter(writeStream))
{
writer.Write(CurrentUser);
peer.SendData(P2PNotices.PeerConnect, writeStream.ToArray());
}
}
peer.isLoggedIn = true;
peer.isConnected = true;
peersToAdd.Add(peer);
}
}
}
if (JoinedGame != null)
JoinedGame(this, peers.Union(peersToAdd).ToList());
}
示例3: ConnectToServer
public void ConnectToServer(IPAddress ip, int port)
{
ServerIP = new IPEndPoint(ip, port);
Peer peer = new Peer(ServerIP, true);
ServerPeer = peer;
AddPeer(peer);
peer.isConnected = true;
using (System.IO.MemoryStream memStream = new System.IO.MemoryStream())
{
using (System.IO.BinaryWriter writer = new System.IO.BinaryWriter(memStream))
{
writer.Write(((IPEndPoint)listener.LocalEndpoint).Port);
writer.Write(CurrentUser);
byte[] bytes = memStream.ToArray();
ServerPeer.SendData(P2PNotices.ClientJoinRequest, bytes);
}
}
}