本文整理汇总了C#中UdpClient类的典型用法代码示例。如果您正苦于以下问题:C# UdpClient类的具体用法?C# UdpClient怎么用?C# UdpClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UdpClient类属于命名空间,在下文中一共展示了UdpClient类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: ReceiveData
// receive thread
private void ReceiveData()
{
client = new UdpClient();
IPEndPoint localEp = new IPEndPoint(IPAddress.Any, port);
client.Client.Bind(localEp);
client.JoinMulticastGroup(IPAddress.Parse(MULTICAST_ADDR));
while (true)
{
try
{
byte[] data = client.Receive(ref localEp);
string text = Encoding.UTF8.GetString(data);
string[] message = text.Split(',');
Vector3 result = new Vector3(float.Parse(message[0]), float.Parse(message[1]), float.Parse(message[2]));
print(">> " + result);
lastReceivedUDPPacket = result;
}
catch (Exception err)
{
print(err.ToString());
}
}
}
开发者ID:intel-cornellcup,项目名称:mini-modbot-simulation,代码行数:28,代码来源:UDPReceive.cs
示例2: ReceiveData
private void ReceiveData(){
client = new UdpClient(port); //Binds udp client to random port
while (true)
{
try
{
IPEndPoint IPEndPoint = new IPEndPoint(IPAddress.Any, 0);
byte[] data = client.Receive(ref IPEndPoint);
string text = Encoding.UTF8.GetString(data);
if(log){
Debug.Log(text);
}
lock(receivedUDPPackets){
receivedUDPPackets.Add(text);
}
}
catch (Exception err)
{
print(err.ToString());
}
}
}
开发者ID:Urauth,项目名称:Finnish-Game-Jam-2016,代码行数:28,代码来源:UDPReceive.cs
示例3: Listen
private void Listen()
{
System.Random myRandom = new System.Random();
udpClient = new UdpClient(7272, AddressFamily.InterNetwork);
var endPoint = default(IPEndPoint);
byte[] bytes;
while (m_shouldRun)
{
try
{
bytes = udpClient.Receive(ref endPoint);
if (bytes == null || bytes.Length == 0)
break;
int offset = 0;
lock (m_threadLock)
{
m_head = FromOculusToUnity(Vector3FromBytes(bytes, ref offset));
m_rHand = FromOculusToUnity(Vector3FromBytes(bytes, ref offset));
//m_rHandRotation = Vector4FromBytes(bytes, ref offset);
m_lHand = FromOculusToUnity(Vector3FromBytes(bytes, ref offset));
//m_lHandRotation = Vector4FromBytes(bytes, ref offset);
m_rightClosed = BoolFromBytes(bytes, ref offset);
}
} catch (ThreadInterruptedException)
{
// Empty on purpose
}
}
}
开发者ID:patricio272,项目名称:VRHackZurich,代码行数:33,代码来源:PositionProvider.cs
示例4: init
public void init()
{
IP = "192.168.15.11";
port = 8051;
remoteEndPoint = new IPEndPoint(IPAddress.Parse(IP), port);
client = new UdpClient();
}
开发者ID:RoySquad,项目名称:KSP_Remote,代码行数:7,代码来源:UDP_Sender.cs
示例5: exportData
private void exportData(ref UdpClient client, ref IPEndPoint anyIP)
{
byte[] data;
string text;
text = "SOT"; // start of table
text = text + System.Environment.NewLine;
data = System.Text.Encoding.ASCII.GetBytes(text);
client.Send(data, data.Length, anyIP);
foreach (var ptr in timeGraphScript.dateTime_val_dic) {
text = ptr.Key.ToString("yyyy/MM/dd HH:mm:ss");
text = text + ",";
text = text + ptr.Value.ToString();
text = text + System.Environment.NewLine;
data = System.Text.Encoding.ASCII.GetBytes(text);
client.Send(data, data.Length, anyIP);
}
text = "EOT"; // end of table
text = text + System.Environment.NewLine;
data = System.Text.Encoding.ASCII.GetBytes(text);
client.Send(data, data.Length, anyIP);
}
开发者ID:yasokada,项目名称:unity-150908-udpTimeGraph,代码行数:25,代码来源:udpReceiverScript.cs
示例6: procComm
void procComm()
{
port = getPort();
string ipadr = getIpadr ();
client = new UdpClient ();
// send
string sendstr = IFmsg.text + System.Environment.NewLine;
byte[] data = ASCIIEncoding.ASCII.GetBytes (sendstr);
client.Send (data, data.Length, ipadr, port);
// receive
client.Client.ReceiveTimeout = 2000; // msec
IPEndPoint remoteIP = new IPEndPoint(IPAddress.Any, 0);
lastRcvd = "";
try {
data = client.Receive (ref remoteIP);
if (data.Length > 0) {
string text = Encoding.ASCII.GetString (data);
lastRcvd = text;
}
} catch (Exception err) {
}
client.Close ();
}
开发者ID:yasokada,项目名称:unity-150830-udpSender,代码行数:27,代码来源:SendButtonScript.cs
示例7: LoadClient
public void LoadClient()
{
client = new UdpClient(System.Convert.ToInt32(port));
receivePoint = new IPEndPoint(IPAddress.Parse(ip),System.Convert.ToInt32(port));
Thread startClient = new Thread(new ThreadStart(start_client));
startClient.Start();
}
开发者ID:TNogisto,项目名称:Tankim-ng,代码行数:7,代码来源:UDPConnectionGUI.cs
示例8: Start
//private CIPC_CS_Unity.CLIENT.CLIENT CIPCclient;
//private Thread thred;
//private FPSAdjuster.FPSAdjuster fps;
// Use this for initialization
void Start()
{
if (this.renderTexture == null )
{
return;
}
this.client = new UdpClient();
this.sendtexture = new Texture2D(this.renderTexture.width, this.renderTexture.height);
if (this.portNumber == 0)
{
this.portNumber = 15000;
}
//if (this.serverPort == 0)
//{
// this.serverPort = 50000;
//}
if (this.IPAdress == "")
{
this.IPAdress = "127.0.0.1";
}
//this.CIPCclient = new CIPC_CS_Unity.CLIENT.CLIENT(this.portNumber, this.IPAdress, this.serverPort);
//this.CIPCclient.Setup(CIPC_CS_Unity.CLIENT.MODE.Sender);
//this.fps = new FPSAdjuster.FPSAdjuster();
//this.fps.Fps = 30;
//this.fps.Start();
//this.thred = new Thread (new ThreadStart(this.sendimage));
//this.thred.Start();
}
开发者ID:0tsukq,项目名称:LabLife,代码行数:38,代码来源:Lablife.cs
示例9: ConnectAsync_StringHost_Success
public async Task ConnectAsync_StringHost_Success()
{
using (var c = new UdpClient())
{
await c.Client.ConnectAsync("114.114.114.114", 53);
}
}
开发者ID:SamuelEnglard,项目名称:corefx,代码行数:7,代码来源:UdpClientTest.cs
示例10: init
// init
public void init(string targetIP, string name)
{
playerName = name;
GameObject.FindGameObjectWithTag("Game").GetComponent<Canvas>().enabled = true;
GameObject.FindGameObjectWithTag("GUI").GetComponent<Canvas>().enabled = false;
print("UDPSend.init()");
port = 8051;
IPAddress[] addrs = Dns.GetHostEntry(Dns.GetHostName()).AddressList;
foreach (var ip in addrs)
{
if (ip.AddressFamily == AddressFamily.InterNetwork)
{
playerIP = ip.ToString();
}
}
remoteEndPoint = new IPEndPoint(IPAddress.Parse(targetIP), port);
client = new UdpClient();
connected = true;
// status
print("Sending to " + targetIP + " : " + port);
print("Player IP is " + playerIP);
}
开发者ID:intel-cornellcup,项目名称:sim-controller,代码行数:26,代码来源:UDPSend2.cs
示例11: Main
public static void Main()
{
byte[] data = new byte[1024];
string input, stringData;
UdpClient udpClient = new UdpClient("127.0.0.1", 9999);
IPEndPoint sender = new IPEndPoint(IPAddress.Any, 0);
string welcome = "Hello";
data = Encoding.ASCII.GetBytes(welcome);
udpClient.Send(data, data.Length);
data = udpClient.Receive(ref sender);
Console.WriteLine("Message received from {0}:", sender.ToString());
stringData = Encoding.ASCII.GetString(data, 0, data.Length);
Console.WriteLine(stringData);
while(true)
{
input = Console.ReadLine();
udpClient.Send(Encoding.ASCII.GetBytes(input), input.Length);
data = udpClient.Receive(ref sender);
stringData = Encoding.ASCII.GetString(data, 0, data.Length);
Console.WriteLine(stringData);
}
udpClient.Close();
}
开发者ID:EdiCarlos,项目名称:MyPractices,代码行数:28,代码来源:udpclient.cs
示例12: ReceiveData
// receive thread
private void ReceiveData() {
client = new UdpClient(port);
while (true) {
try {
// Bytes empfangen.
IPEndPoint anyIP = new IPEndPoint(IPAddress.Any, 0);
byte[] data = client.Receive(ref anyIP);
// Bytes mit der UTF8-Kodierung in das Textformat kodieren.
string text = Encoding.UTF8.GetString(data);
// Den abgerufenen Text anzeigen.
print(">> " + text);
// latest UDPpacket
lastReceivedUDPPacket=text;
// ....
allReceivedUDPPackets=allReceivedUDPPackets+text;
}
catch (Exception err) {
print(err.ToString());
}
}
}
开发者ID:adrianniebla,项目名称:VideoJuegoDistribuido,代码行数:29,代码来源:UDPReceive.cs
示例13: ConnectAsync_IPAddressHost_Success
public async Task ConnectAsync_IPAddressHost_Success()
{
using (var c = new UdpClient())
{
await c.Client.ConnectAsync(IPAddress.Parse("114.114.114.114"), 53);
}
}
开发者ID:charygao,项目名称:corefx,代码行数:7,代码来源:UdpClientTest.cs
示例14: Program
//public Program()
//{
// socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
// localEP = new IPEndPoint(IPAddress.Any,port);
// socket.Bind(localEP);
// ConnectionEstablished = false;
//}
public Program()
{
localEP = new IPEndPoint(IPAddress.Any, port);
server = new UdpClient(localEP);
//IPEndPoint
//client.Send()
}
开发者ID:IlyichExperiments,项目名称:UDP_XO,代码行数:14,代码来源:Program.cs
示例15: ReceiveData
//受信スレッド
private void ReceiveData()
{
//udpクライアント設定
udpClient = new UdpClient(port);
while(threadAvairable)
{
try
{
if(udpClient.Available > 0)
{
IPEndPoint ipEndPoint = new IPEndPoint(IPAddress.Any, 0);
byte[] data = udpClient.Receive(ref ipEndPoint);
recievedDataStr = Encoding.UTF8.GetString(data);
isDataRecieved = true;
}
}
catch(Exception err)
{
Debug.LogError(err.Message);
DebugConsole.LogError(err.Message);
break;
}
}
}
开发者ID:sgyli7,项目名称:GarageKit_for_Unity,代码行数:27,代码来源:UDPReciever.cs
示例16: Connect
public bool Connect()
{
try
{
serverRemote = new IPEndPoint(IPAddress.Parse(ipAddress), portNumber);
udpClient = new UdpClient();
udpClient.Connect(serverRemote);
if(udpClient.Client.Connected)
{
Debug.Log("connected!");
sendUDPPacket("ANYONE OUT THERE?");
//byte[] data = Encoding.UTF8.GetBytes(toSend);
//client.Send(data, data.Length, serverRemote);
//client.SendTimeout(serverRemote, data);
}
}
catch(Exception ex)
{
print ( ex.Message + " : OnConnect");
}
isConnected = true;
if ( udpClient == null ) return false;
return udpClient.Client.Connected;
}
开发者ID:putty174,项目名称:Pong,代码行数:29,代码来源:Sockets.cs
示例17: Start
void Start()
{
server = new UdpClient(port);
isReceiving = true;
Data = string.Empty;
StartCoroutine("ReceiverStart");
}
开发者ID:kleberandrade,项目名称:car-simulator,代码行数:7,代码来源:UdpReceiver.cs
示例18: WakeUp
public static void WakeUp(byte[] mac, string ip = "255.255.255.255", int port = 9)
{
using (var client = new UdpClient {EnableBroadcast = true})
{
client.Send(CreateMagickPacket(mac), MagickPacketSize, ip, port);
}
}
开发者ID:MisterHoker,项目名称:NetworkLibrary,代码行数:7,代码来源:WakeOnLan.cs
示例19: Connect
// Connect for receiving messages
public bool Connect(int localPort)
{
Disconnect();
receiveDone.Reset();
// Connect to a local port.
try
{
localEP = new IPEndPoint(IPAddress.Any, localPort);
// Create a UDP Client.
clientReceive = new UdpClient(localEP);
if (ConnectedStateChanged != null) ConnectedStateChanged(this, new ConnectedStateChangedEventArgs(true));
// Setup the receiver client thread
receiverTask = new Thread(ReceiverLoop);
receiverTask.Start();
// Signal that the connection has been made.
connectDone.Set();
}
catch (Exception e)
{
Disconnect();
//
Console.WriteLine(e.ToString());
}
return IsConnected;
}
开发者ID:jarrettv,项目名称:HomeGenie,代码行数:31,代码来源:UdpClient.cs
示例20: RecieveDatagram
void RecieveDatagram()
{
UdpClient receivingUdpClient = new UdpClient ( 35143 );
IPEndPoint RemoteIpEndPoint = new IPEndPoint ( IPAddress.Any, 0 );
while ( true )
{
try {
Byte[] receiveBytes = receivingUdpClient.Receive ( ref RemoteIpEndPoint );
returnData = Encoding.Unicode.GetString ( receiveBytes );
if ( returnData.Substring ( 0, 17 ) == "[2CatStudios:UMP]" )
{
UnityEngine.Debug.Log ( "Recieved '" + returnData.ToString () + "' This message was sent on " + RemoteIpEndPoint.Address.ToString() + " via the port " + RemoteIpEndPoint.Port.ToString ());
returnData = returnData.Substring ( 17 );
} else {
UnityEngine.Debug.Log ( "Data was recieved, but it was not expected." );
}
}
catch ( Exception e )
{
UnityEngine.Debug.Log ( e.ToString ());
returnData = e.ToString ();
}
}
}
开发者ID:2CatStudios,项目名称:UnityMusicPlayer,代码行数:31,代码来源:Sockets.cs
注:本文中的UdpClient类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论