private void HeartBeat() { while (!_listening) { Thread.Sleep(100); } while (_running) { Thread.Sleep(3000); if (udpClient == null) { continue; } udpClient.Send(new byte[] { }, 0, _remoteIP, _dataPort); } }
// TODO: convert this to Junit internal static void TestRequest(XDR request, XDR request2) { try { DatagramSocket clientSocket = new DatagramSocket(); IPAddress IPAddress = Sharpen.Extensions.GetAddressByName("localhost"); byte[] sendData = request.GetBytes(); byte[] receiveData = new byte[65535]; DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.Length, IPAddress , Nfs3Constant.SunRpcbind); clientSocket.Send(sendPacket); DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.Length ); clientSocket.Receive(receivePacket); clientSocket.Close(); } catch (UnknownHostException) { System.Console.Error.WriteLine("Don't know about host: localhost."); System.Environment.Exit(1); } catch (IOException) { System.Console.Error.WriteLine("Couldn't get I/O for " + "the connection to: localhost." ); System.Environment.Exit(1); } }
public static bool sendMove(int deltax, int deltay) { buffer = new byte[BUFFER_SIZE]; string s = new String("e1:" + deltax + "," + deltay); buffer = Encoding.ASCII.GetBytes(s); try { // pout = new DatagramPacket(buffer, buffer.Length, new InetAddress(), port); try { socket.Send(pout); return(true); } catch (IOException e) { // TODO Auto-generated catch block //e.StackTrace(); connected = false; return(false); } } catch (UnknownHostException e) { // TODO Auto-generated catch block //e.printStackTrace(); connected = false; return(false); } }
/// <summary>Sends Ganglia Metrics to the configured hosts</summary> /// <exception cref="System.IO.IOException"/> protected internal virtual void EmitToGangliaHosts() { try { foreach (EndPoint socketAddress in metricsServers) { if (socketAddress == null || !(socketAddress is IPEndPoint)) { throw new ArgumentException("Unsupported Address type"); } IPEndPoint inetAddress = (IPEndPoint)socketAddress; if (inetAddress.IsUnresolved()) { throw new UnknownHostException("Unresolved host: " + inetAddress); } DatagramPacket packet = new DatagramPacket(buffer, offset, socketAddress); datagramSocket.Send(packet); } } finally { // reset the buffer for the next metric to be built offset = 0; } }
public override void OnOutputBufferAvailable(MediaCodec codec, int index, MediaCodec.BufferInfo info) { ByteBuffer outputBuffer = codec.GetOutputBuffer(index); byte[] outputArray = new byte[outputBuffer.Remaining()]; outputBuffer.Get(outputArray); DatagramPacket packet = new DatagramPacket(outputArray, outputArray.Length, InetAddress.GetByAddress(new byte[] { 192, 168, 0, 31 }), 9482); _udpSocket.Send(packet); codec.ReleaseOutputBuffer(index, false); }
public override int Send(RTRequest request) { MemoryStream ms = PooledObjects.MemoryStreamPool.Pop(); try { ms.Position = 0; Packet p = request.ToPacket(session, true); try { Packet.SerializeLengthDelimited(ms, p); } finally { PooledObjects.PacketPool.Push(p); } try { #if __WINDOWS__ Task t = Task.Run(async() => { byte[] newArray = ms.ToArray(); Array.Resize <byte>(ref newArray, (int)ms.Position); DataWriter writer = new DataWriter(client.OutputStream); writer.WriteBytes(newArray); await writer.StoreAsync(); await writer.FlushAsync(); writer.DetachStream(); writer.Dispose(); }); t.Wait(); //client.OutputStream.AsStreamForWrite().WriteAsync(newArray, 0, (int)ms.Position); #else client.Send(ms.GetBuffer(), (int)ms.Position); #endif } catch (Exception e) { System.Diagnostics.Debug.WriteLine(e); session.Log("fastConnection", GameSparksRT.LogLevel.INFO, "Exception sending UDP {0}", e.Message); } return((int)ms.Position); } finally { PooledObjects.MemoryStreamPool.Push(ms); } }
/// <exception cref="System.IO.IOException"/> /// <exception cref="System.Exception"/> public virtual void TestRegistration() { XDR req = new XDR(); RpcCall.GetInstance(++xid, RpcProgramPortmap.Program, RpcProgramPortmap.Version, RpcProgramPortmap.PmapprocSet, new CredentialsNone(), new VerifierNone()).Write( req); PortmapMapping sent = new PortmapMapping(90000, 1, PortmapMapping.TransportTcp, 1234 ); sent.Serialize(req); byte[] reqBuf = req.GetBytes(); DatagramSocket s = new DatagramSocket(); DatagramPacket p = new DatagramPacket(reqBuf, reqBuf.Length, pm.GetUdpServerLoAddress ()); try { s.Send(p); } finally { s.Close(); } // Give the server a chance to process the request Thread.Sleep(100); bool found = false; IDictionary <string, PortmapMapping> map = (IDictionary <string, PortmapMapping>)Whitebox .GetInternalState(pm.GetHandler(), "map"); foreach (PortmapMapping m in map.Values) { if (m.GetPort() == sent.GetPort() && PortmapMapping.Key(m).Equals(PortmapMapping. Key(sent))) { found = true; break; } } Assert.True("Registration failed", found); }
/// <summary>Udp /// 同一Wi-fiに接続している全端末に対してブロードキャスト送信を行う /// </summary> void sendBroadcast() { string myIpAddress = getIpAddress(); int count = 0; //送信回数を10回に制限する while (count < 10) { try { DatagramSocket udpSocket = new DatagramSocket(udpPort); udpSocket.Broadcast = true; //public DatagramPacket(byte[] buf, int length, InetAddress address, int port); byte[] IpAddressdata = System.Text.Encoding.UTF8.GetBytes(myIpAddress); DatagramPacket packet = new DatagramPacket(IpAddressdata /*myIpAddress.getBytes()*/, myIpAddress.Length, getBroadcastAddress(), udpPort); udpSocket.Send(packet); udpSocket.Close(); } catch (SocketException e) { e.PrintStackTrace(); } catch (IOException e) { e.PrintStackTrace(); } //5秒待って再送信を行う try { Thread.Sleep(5000); count++; } catch (InterruptedIOException e) { e.PrintStackTrace(); } } }
/// <exception cref="System.IO.IOException"/> public virtual void Run() { IPAddress IPAddress = Extensions.GetAddressByName(host); byte[] sendData = request.GetBytes(); byte[] receiveData = new byte[65535]; // Use the provided socket if there is one, else just make a new one. DatagramSocket socket = this.clientSocket == null ? new DatagramSocket() : this.clientSocket; try { DatagramPacket sendPacket = new DatagramPacket(sendData, sendData.Length, IPAddress , port); socket.Send(sendPacket); socket.SetSoTimeout(500); DatagramPacket receivePacket = new DatagramPacket(receiveData, receiveData.Length ); socket.Receive(receivePacket); // Check reply status XDR xdr = new XDR(Arrays.CopyOfRange(receiveData, 0, receivePacket.GetLength())); RpcReply reply = RpcReply.Read(xdr); if (reply.GetState() != RpcReply.ReplyState.MsgAccepted) { throw new IOException("Request failed: " + reply.GetState()); } } finally { // If the client socket was passed in to this UDP client, it's on the // caller of this UDP client to close that socket. if (this.clientSocket == null) { socket.Close(); } } }
/// <exception cref="System.IO.IOException"/> protected internal virtual void EmitMetric(string name, string type, string value ) { string units = GetUnits(name); int slope = GetSlope(name); int tmax = GetTmax(name); int dmax = GetDmax(name); offset = 0; Xdr_int(0); // metric_user_defined Xdr_string(type); Xdr_string(name); Xdr_string(value); Xdr_string(units); Xdr_int(slope); Xdr_int(tmax); Xdr_int(dmax); foreach (EndPoint socketAddress in metricsServers) { DatagramPacket packet = new DatagramPacket(buffer, offset, socketAddress); datagramSocket.Send(packet); } }
private void Send(byte[] data, model.RtpMidiServer rtpMidiServer) { Log.Debug("RtpMidi", "Sending data {} to server {}", BitConverter.ToString(data).Replace("-", ""), rtpMidiServer); socket.Send(new DatagramPacket(data, data.Length, rtpMidiServer.InetAddress, rtpMidiServer.Port)); }
public void Send(string data, string address, int port) { byte[] b = System.Text.Encoding.ASCII.GetBytes(data); m_udp.Send(b, b.Length, address, port); }
private void broadcast(byte[] data) { _udpClient.Send(data, data.Length, _address, _port); }
private void Send(RtpMidiCommand midiCommand, model.RtpMidiServer rtpMidiServer) { byte[] invitationAcceptedBytes = midiCommand.ToByteArray(); socket.Send(new DatagramPacket(invitationAcceptedBytes, invitationAcceptedBytes.Length, rtpMidiServer.InetAddress, rtpMidiServer.Port)); }
public void Send(string message) { byte[] dgram = Encoding.Default.GetBytes(message); _impl.Send(dgram, dgram.Length, destIP, destPort); #endif }
private void _sendData(byte[] data, string hostName, int port) { udpClient.Send(data, data.Length, hostName, port); }