// Use this for initialization void Start() { // create receiver. udpReceiver = new UdpReceiver( IP.LocalIPAddressSync(), 9339, bytes => { Debug.Log("received udp data:" + Encoding.UTF8.GetString(bytes)); } ); // send data to receiver. udpSender = new UdpSender( IPAddress.Parse("127.0.0.1"), 9339 ); udpSender.Send( Encoding.UTF8.GetBytes("hello via udp.") ); }
public UdpMulticastingChannel(string address, int port) { MessageParserFactory = new MessageParserFactory(); MessageParser parser = MessageParserFactory.Create(); UdpReceiver receiveSocket = new UdpReceiver(address, port); receiveSocket.ReceiveEvent += parser.OnBytes; receiveSocket.Start(); var sendSocket = new UdpSource(address, port); sendSocket.Start(); var asyncWriter = new DaemonWritter(sendSocket); //var asyncWriter = new BatchWriter(sendSocket,1500); TopicPublisher = new TopicPublisher(asyncWriter); TopicPublisher.Start(); _disposables.Add(receiveSocket); _disposables.Add(sendSocket); }
private void Form1_Load(object sender, EventArgs e) { this.lstMessages.Items.Clear(); this.lstPeers.Items.Clear(); manager = new MessageManager(); connections = new Dictionary <User, ClientConnection>(); IPAddress[] addresses = Global.getLocalIPAddresses(); this.cmbAddresses.Items.AddRange(addresses); if (addresses.Length > 0) { this.cmbAddresses.SelectedIndex = 0; } udpReceivers = new List <UdpReceiver>(); foreach (var address in addresses) { var udpReceiver = new UdpReceiver(this, address); udpReceiver.ServerFound += Broadcast_ServerFound; udpReceiver.Start(); udpReceivers.Add(udpReceiver); } }
private static async Task Main(string[] args) { using (var transceiver = new UdpTransceiver(IPAddress.Parse("192.168.10.1"), 8889)) using (var stateReceiver = new UdpReceiver(8890)) using (var videoReceiver = new UdpReceiver(11111)) using (var repository = new SqliteRepository((null, "tello.udp.sqlite"))) { var testType = args.Length == 1 && args[0] == "joy" ? TestType.JoyStick : TestType.WayPoint; switch (testType) { case TestType.JoyStick: flightTest = new JoyStickFlightTest( repository, transceiver, stateReceiver, videoReceiver); break; case TestType.WayPoint: flightTest = new CommandFlightTest( repository, transceiver, stateReceiver, videoReceiver); break; default: break; } await flightTest.Invoke(); } }
public void ReceiveNotifications() { new Thread(() => { while (true) { string[] message = Encoding.ASCII.GetString(UdpReceiver.Receive(ref remoteEndPoint)).Split(' '); string request = message[0]; Guid remoteGuid = Guid.Parse(message[1]); if (request == "add") { if (!copies.ContainsKey(remoteGuid)) { copies[remoteGuid] = remoteEndPoint.Address; Console.WriteLine(string.Join("\n", GetJoinMessage(remoteGuid), CopiesCountMessage, CopiesListing, Parameters.Delimiters)); } timeouts[remoteGuid] = 0; } } }).Start(); }
public IEnumerator SetReceiverThenSend() { var received = false; var port = 8888; udpReceiver = new UdpReceiver( IP.LocalIPAddressSync(), port, bytes => { True(bytes.Length == 4); received = true; } ); // send udp data. udpSender = new UdpSender(IP.LocalIPAddressSync(), port); udpSender.Send(new byte[] { 1, 2, 3, 4 }); yield return(WaitUntil( () => received, () => { throw new TimeoutException("failed."); } )); }
public ReceiveTxSyslog(IPEndPoint listener, uint receivercount) { this.Receiver = new UdpReceiver(listener, receivercount); }
private void OnPacketReceived(UdpReceiver receiver, int localPort, IPEndPoint remoteEndPoint, byte[] packet) { STUNMessage stunMessage = STUNMessage.ParseSTUNMessage(packet, packet.Length); switch (stunMessage.Header.MessageType) { case STUNMessageTypesEnum.Allocate: logger.LogDebug($"MockTurnServer received Allocate request from {remoteEndPoint}."); if (_relaySocket == null) { _clientEndPoint = remoteEndPoint; // Create a new relay socket. NetServices.CreateRtpSocket(false, _listenAddress, 0, out _relaySocket, out _); _relayEndPoint = _relaySocket.LocalEndPoint as IPEndPoint; logger.LogDebug($"MockTurnServer created relay socket on {_relayEndPoint}."); _relayListener = new UdpReceiver(_relaySocket); _relayListener.OnPacketReceived += OnRelayPacketReceived; _relayListener.OnClosed += (reason) => logger.LogDebug($"MockTurnServer relay on {_relayEndPoint} closed."); _relayListener.BeginReceiveFrom(); } STUNMessage allocateResponse = new STUNMessage(STUNMessageTypesEnum.AllocateSuccessResponse); allocateResponse.Header.TransactionId = stunMessage.Header.TransactionId; allocateResponse.AddXORMappedAddressAttribute(remoteEndPoint.Address, remoteEndPoint.Port); allocateResponse.AddXORAddressAttribute(STUNAttributeTypesEnum.XORRelayedAddress, _relayEndPoint.Address, _relayEndPoint.Port); _clientSocket.SendTo(allocateResponse.ToByteBuffer(null, false), remoteEndPoint); break; case STUNMessageTypesEnum.BindingRequest: logger.LogDebug($"MockTurnServer received Binding request from {remoteEndPoint}."); STUNMessage stunResponse = new STUNMessage(STUNMessageTypesEnum.BindingSuccessResponse); stunResponse.Header.TransactionId = stunMessage.Header.TransactionId; stunResponse.AddXORMappedAddressAttribute(remoteEndPoint.Address, remoteEndPoint.Port); _clientSocket.SendTo(stunResponse.ToByteBuffer(null, false), remoteEndPoint); break; case STUNMessageTypesEnum.CreatePermission: logger.LogDebug($"MockTurnServer received CreatePermission request from {remoteEndPoint}."); STUNMessage permResponse = new STUNMessage(STUNMessageTypesEnum.CreatePermissionSuccessResponse); permResponse.Header.TransactionId = stunMessage.Header.TransactionId; _clientSocket.SendTo(permResponse.ToByteBuffer(null, false), remoteEndPoint); break; case STUNMessageTypesEnum.SendIndication: logger.LogDebug($"MockTurnServer received SendIndication request from {remoteEndPoint}."); var buffer = stunMessage.Attributes.Single(x => x.AttributeType == STUNAttributeTypesEnum.Data).Value; var destEP = (stunMessage.Attributes.Single(x => x.AttributeType == STUNAttributeTypesEnum.XORPeerAddress) as STUNXORAddressAttribute).GetIPEndPoint(); logger.LogDebug($"MockTurnServer relaying {buffer.Length} bytes to {destEP}."); _relaySocket.SendTo(buffer, destEP); break; default: logger.LogDebug($"MockTurnServer received unknown STUN message from {remoteEndPoint}."); break; } }
public ReceiveTxSyslog(IPEndPoint listener, uint receivercount) { Receiver = new UdpReceiver(listener, receivercount); }
public IEnumerator SetReceiverThenSendManyTimesWithValidation() { var count = 1000; var receivedCount = 0; var port = 8888; try { var data = new byte[100]; for (var i = 0; i < data.Length; i++) { data[i] = (byte)UnityEngine.Random.Range(byte.MinValue, byte.MaxValue); } // validate by hash. checking send data == received data or not. var md5 = MD5.Create(); var origin = md5.ComputeHash(data); var hashLen = origin.Length; // add hash data to head of new data. var newData = new byte[data.Length + hashLen]; for (var i = 0; i < newData.Length; i++) { if (i < hashLen) { newData[i] = origin[i]; } else { newData[i] = data[i - hashLen]; } } udpReceiver = new UdpReceiver( IP.LocalIPAddressSync(), port, bytes => { True(bytes.Length == newData.Length); var hash = md5.ComputeHash(bytes, hashLen, bytes.Length - hashLen); for (var i = 0; i < hash.Length; i++) { True(hash[i] == bytes[i]); } receivedCount++; } ); // send udp data. udpSender = new UdpSender(IP.LocalIPAddressSync(), port); for (var i = 0; i < count; i++) { udpSender.Send(newData); } } catch (Exception e) { Fail(e.ToString()); } yield return(WaitUntil( () => count == receivedCount, () => { throw new TimeoutException("failed. receivedCount:" + receivedCount); } )); }
internal F12019UdpReceiver(Action <AllPacketsComposition> sessionStartedHandler, Action <AllPacketsComposition> newDataHandler, int connectionPort) { _port = connectionPort; _udpReceiver = new UdpReceiver(_port); _dataSetCompositor = new DataSetCompositor(sessionStartedHandler, newDataHandler); }
public ServerComManager(System.Net.Sockets.UdpClient udpClient) { log4net.Config.XmlConfigurator.Configure(); _udpReceiver = new UdpReceiver(udpClient); _udpReceiver.ReceivedData += _udpReceiver_ReceivedData; }
public void Dispose() { UdpReceiver.Dispose(); }
public static void DisposalTest() { using var receiver = new UdpReceiver(); }
public PCars2UdpReceiver() { _udpReceiver = new UdpReceiver(5606); }
/// <summary> /// Open to receive messages on specified port and (optionally) from specified multicast IP address. /// Returns success status. /// </summary> public bool Open(int port, string multicastAddress = "") { // Ensure that we have a receiver, even when not in Play mode. if (_receiver == null) { _receiver = new UdpReceiver(OnDataReceivedAsync); } // Close and existing receiver. if (isOpen) { Close(); } // Validate port number range. if (port < OscConst.portMin || port > OscConst.portMax) { StringBuilder sb = OscDebug.BuildText(this); sb.Append("Open failed. Port "); sb.Append(port); sb.Append(" is out of range.\n"); Debug.LogWarning(sb.ToString()); return(false); } _port = port; // Derive mode from multicastAddress. IPAddress multicastIP; if (!string.IsNullOrEmpty(multicastAddress) && IPAddress.TryParse(multicastAddress, out multicastIP)) { if (Regex.IsMatch(multicastAddress, OscConst.multicastAddressPattern)) { _mode = OscReceiveMode.UnicastBroadcastMulticast; _multicastAddress = multicastAddress; } else { StringBuilder sb = OscDebug.BuildText(this); sb.Append("Open failed. Multicast IP address "); sb.Append(multicastAddress); sb.Append(" is out not valid. It must be in range 224.0.0.0 to 239.255.255.255.\n"); Debug.LogWarning(sb.ToString()); return(false); } } else { _multicastAddress = string.Empty; _mode = OscReceiveMode.UnicastBroadcast; } // Set buffer size. _receiver.bufferSize = _udpBufferSize; // Try open. if (!_receiver.Open(_port, _multicastAddress)) { Debug.Log("Failed to open"); return(false); } // Deal with the success if (Application.isPlaying) { StringBuilder sb = OscDebug.BuildText(this); if (_mode == OscReceiveMode.UnicastBroadcast) { sb.Append("Ready to receive unicast and broadcast messages on port "); } else { sb.Append("Ready to receive multicast messages on address "); sb.Append(_multicastAddress); sb.Append(", unicast and broadcast messages on port "); } sb.Append(_port); sb.AppendLine(); Debug.Log(sb.ToString()); } return(true); }
/// <summary> /// 创建接收器 /// </summary> /// <param name="url">url地址,诸如:udp://127.0.0.1:9999</param> /// <param name="ccrParameter">Ccr运行参数</param> /// <param name="bufferPoolParameter">缓冲池参数</param> /// <param name="contained">是否由通信器统一管理</param> /// <returns>数据接收器。如果是null,则表示数据接收器已经存在</returns> /// <exception cref="System.ArgumentException">当不能创建时,抛出异常</exception> /// <exception cref="System.Net.Sockets.SocketException">当不能创建时,抛出异常</exception> public DataReceiver CreateReceiver(string url, CcrParameter ccrParameter, BufferPoolParameter bufferPoolParameter, bool contained) { DataReceiver receiver = null; PipelineAddress sa = PipelineAddress.Parse(url); switch (sa.CommuncationType) { case CommuncationType.Tcp: receiver = new TcpSharpReceiver((IPEndPoint)sa.Address, ccrParameter, bufferPoolParameter); break; case CommuncationType.Udp: case CommuncationType.Udps: receiver = new UdpSharpReceiver((IPEndPoint)sa.Address, ccrParameter, bufferPoolParameter); break; case CommuncationType.Udpa: receiver = new UdpReceiver((IPEndPoint)sa.Address, ccrParameter); break; case CommuncationType.Msmq: receiver = new MsmqReceiver((string)sa.Address, ccrParameter); break; case CommuncationType.Sms: throw new ArgumentException(String.Format("NotSupportedCommunication:{0}", url)); case CommuncationType.Http: throw new ArgumentException(String.Format("NotSupportedCommunication:{0}", url)); case CommuncationType.SharedMemory: receiver = new ShareMemoryReceiver((ShareMemoryEndPoint)sa.Address, ccrParameter); break; case CommuncationType.SharedRegion: break; case CommuncationType.Ftp: break; case CommuncationType.Unknown: throw new ArgumentException(String.Format("NotSupportedCommunication:{0}", url)); default: throw new ArgumentException(String.Format("Illegal url: {0}", url)); } if (receiver != null && contained) { m_receivers.Add(receiver.LocalEndPoint, receiver); } return receiver; }
public MatchMakerClient(int discoveryPort, BinaryObjectDictionary dictionary) { udpReceiver = new UdpReceiver(discoveryPort + 1); this.client = new DiscoveryClient(new UdpBroadcaster(discoveryPort), udpReceiver); this.dictionary = dictionary; }