导航:首页 > 编程语言 > java广播地址

java广播地址

发布时间:2022-08-05 00:05:49

‘壹’ java rtpstream怎么用

1.出现Local Data AddressDoes not belong to any of this hosts local interfaces错误:
主要问题是发送视频和音频的程序需要在服务器上运行,你可以选择Win2000 Server 或者Win2003 Server,问题就解决了。
2.传输声音和视频的方法如下:
a.传输声音或者视频文件
编译完AVTransmit2.java后,再命令提示符中输入命令:java AVTransmit2 file:test.wav 224.224.123.123 22222(注意文件的类型是.wav 或者.mov 、.mpg的文件,不可以是.mp3、.rmvb等其他不支持的文件。传输支持文件格式有限,我也没有办法,应该在添加相关的插件就行了,希望大家提供帮助),其中test.wav即传输的文件名,224.224.123.123为多播地址,22222为端口号.
接收方法:编译完AVReceive.java后,在命令提示符中输入命令:java AVReceive 224.224.123.123/22222即可接受到声音文件
b.传输麦克风的音频,在传输之前先检查电脑录音控制的选项是否为麦克风.(步骤:打开桌面任务栏上的音量控制,选择选项---->属性----->调节音量选择录音,之后在下面的音量控制属性中选中麦克风。单击确定。接着跳到录音控制,选择麦克风就行了)。使用的命令是:java AVTransmit2 dsound:// 224.224.123.123 22222,此时就开始传输声音了。
接收方法同上
c.传输摄相头视频,使用的命令为:java AVTransmit2 vfw://0 224.224.123.123 22222
接收方法同上
d.关于广播、组播和单播
广播:对于局域网广播你可以使用广播的地址,如你的子网掩码是255.255.225.0,即C类的默认子网掩码,你的广播地址可以是192.168.3.255。(注:我的局域网ip地址分配为192.168.3.X)。如子网掩码不同,你可以参照相关的网络常识自己推算。
接收时也使用多播地址来接受,假如发送方的机器地址为:192.168.3.46。发送时在发送放的机器上运行java AVTransmit2 file:test.wav 192.168.3.255 22222,接收时使用java AVReceive2 224.224.123.123 22222。才能完成接收.这和网上的说法不同,端口号不要填错,地址任意。按网上的说法,使用的接收地址应为为192.168.3.46,可是我没有成功,总是出现Local Data AddressDoes not belong to any of this hosts local interfaces的错误,而使用多播地址反而成功了。具体的参数我就不多介绍了,有问题可以给我留言。
组播:使用组播地址发送,组播地址接收即可
单播:假如你只想给某台机子发送,那么就在发送方输入命令,如:java AVTransmit2 file:test.wav 192.168.3.47 22222,这时你只会将声音流文件发送给47号计算机。而接受时还是使用多播地址,如java AVReceive2 224.224.123.123 22222。这是就听到声音了。
总之,使用RTP传输,在接受时都在使用多播地址,在发送时根据情况而定,至于ttl你可以不去管它。不只大家是怎么实现的,反正网上的资料让我变的很失望,真正的成功源于实践。下面摘取一段让大家欣赏(尽信书则不如无书)
网上摘取:
Transmitting Audio and Video over RTP
The AVTransmit2 class is very similar to the VideoTransmit, but uses RTP managers
to send the video and audio streams.
Since the media tracks are transmitted in multiple sessions, you'll need to
use one Player per track on the receive side. Using JMStudio, you can
start multiple Players from the "File" menu using the "New Window"
item. Then either:
use the "Open URL..." item to open one RTP session per track. The URL to use is:

rtp://<sourceIP>:<port>/media
Where <sourceIP> is the IP address of the RTP session and the port
number is the same one that is used on the transmitting side.
OR

Open RTP session and specify <sourcIP> and <port>

How to run this sample
1. Run AVTransmit2 with the required 3 command line parameters
For example, we can use any of the following:
- java AVTransmit2 file:clips/clip01mpg.mpg 224.112.112.112 22222

2. To receive the transmission on the client side use JMStudio:
- use open RTP session and specify group: 224.112.112.112 & port: 22222
AND use FILE -> New Window and open RTP sesssion with port 22224.

OR
- use open URL and specify: rtp://224.112.112.112:22222/video
AND use FILE -> New Window and open URL with 22224/audio

Notes:

You should run 1. then 2., otherwise AVTransmit2 will find the port number used.
You can also use the program to send only audio or video as follows:

- java AVTransmit2 javasound://0 224.112.112.112 22222 (audio only)
- java AVTransmit2 vfw://0 224.112.112.112 22222 (video only)
In such case create only one instance of JMStudio.

Use Unicast:

- java AVTransmit2 file:clip01.mpg 128.82.4.7 22222
Where 128.82.4.7 is the receicver address.
If the sender address is 128.82.4.9 it will use port 22222 as well
to send out data. In this case the receiver (e.g., JMStudio)
should specify the sender as: 128.82.4.9 22222.
Therefore to use unicast you should have two machines since
you can not use the same port for both sender and receiver.
Receiving Audio and Video using RTP
AVReceive2 uses the RTPManager API to receive RTP transmissions.
AVReceive2 performs the following tasks:
Open one RTP session per session address given.
Listen for the NewReceiveStreamEvent from the ReceiveStreamListener.
Create a JMF Player for each stream received for playback.
This sample program can be used in conjunction with JMStudio,
the AVTransmit2 sample or any other RTP compliant transmitter.
The IP address should be the address of the computer which transmits the data; or the multicast address if multicast is being used for the transmission.
The ports should be the same as what's being used by the transmitter.
How to run this sample
1. Run AVTransmit2 with the required 3 command line parameters
For example:
- java AVTransmit2 file:clips/clip01mpg.mpg 224.112.112.112 1234
2. Run AVReceive2 and specify the RTP session addresses to receive from.
For example:
- java AVReceive2 224.112.112.112/1234 224.112.112.112/1236
to simultaneously receive 2 different RTP sessions (video and audio).
Note: because of port reuse, it must run in this order, 1 then 2.

‘贰’ 有谁知道怎样使用java编写ping程序

jpcap你要自己下好相应的包和配置,不知道的就在网上搜吧··

import java.net.InetAddress;
import java.util.ArrayList;
import java.util.GregorianCalendar;
import java.util.List;
import jpcap.JpcapCaptor;
import jpcap.JpcapSender;
import jpcap.NetworkInterface;
import jpcap.packet.EthernetPacket;
import jpcap.packet.ICMPPacket;
import jpcap.packet.IPPacket;

public class JPing {

private NetworkInterface[] devices = JpcapCaptor.getDeviceList();
private JpcapSender sender;
private JpcapCaptor jpcap;
private ICMPPacket icmpPacket;
private List<String> listResult = new ArrayList<String>();

/**
* 组织ICMP报文发送,并开启线程接收报文
* @param ip
*/
public void ping(String ip) {
try {
jpcap = JpcapCaptor.openDevice(devices[0], 200, false, 20);
sender = jpcap.getJpcapSenderInstance();
jpcap.setFilter("icmp", true);// 过滤器,只接受ICMP报文
icmpPacket = new ICMPPacket();
icmpPacket.type = ICMPPacket.ICMP_ECHO; // 发送回显请求报文

icmpPacket.setIPv4Parameter(0, false, false, false, 0, false,
false, false, 0, 1010101, 100, IPPacket.IPPROTO_ICMP,
devices[0].addresses[1].address, InetAddress.getByName(ip));
// 随意的32bytes数据
icmpPacket.data = "".getBytes();
EthernetPacket ethernetPacket = new EthernetPacket();
ethernetPacket.frametype = EthernetPacket.ETHERTYPE_IP;
ethernetPacket.src_mac = devices[0].mac_address;
// 广播地址
ethernetPacket.dst_mac = new byte[] { (byte) 0xff, (byte) 0xff,
(byte) 0xff, (byte) 0xff, (byte) 0xff, (byte) 0xff };
icmpPacket.datalink = ethernetPacket;
listResult.add("Pinging " + icmpPacket.dst_ip + " with "
+ icmpPacket.data.length + " bytes of data: ");
startCapThread(jpcap);
for (int i = 0; i < 5; i++) {
icmpPacket.sec = 0;
//icmpPacket.usec = System.currentTimeMillis();
icmpPacket.usec = new GregorianCalendar().getTimeInMillis();// 记录发送时间
icmpPacket.seq = (short) (1000 + i);
icmpPacket.id = (short) (999 + i);
sender.sendPacket(icmpPacket);
try {
Thread.sleep(1000);
} catch (Exception e) {
e.printStackTrace();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}

/**
* 接收ICMP报文
* @param jpcap
*/
public void getIcmpPacket(JpcapCaptor jpcapCaptor) {
try {
while (true) {
long tmp = 0;
String tmpStr = null;
ICMPPacket rp;

rp = (ICMPPacket) jpcapCaptor.getPacket();

if ((rp != null) && (rp.seq - rp.id == 1)
&& (rp.type == ICMPPacket.ICMP_ECHOREPLY)) {// 若是ICMP回应报文,则列出。。。
tmp = (rp.sec * 1000 + rp.usec / 1000 - icmpPacket.sec
* 1000 - icmpPacket.usec); // 计算发送与接受的时间差
if (tmp <= 0)
tmpStr = " < 1 ms ";
else
tmpStr = "= " + tmp + " ms ";

System.out.println("Reply from "
+ rp.src_ip.getHostAddress() + ": bytes = "
+ rp.data.length + " time " + tmpStr + "TTL = "
+ rp.hop_limit);

listResult.add("Reply from " + rp.src_ip.getHostAddress()
+ ": bytes = " + rp.data.length + " time " + tmpStr
+ "TTL = " + rp.hop_limit);
}
}
} catch (Exception e) {
e.printStackTrace();
}

}

/**
* 接收ICMP报文
* @param jpcap
*/
public void startCapThread(final JpcapCaptor jpcap) {

Runnable runner = new Runnable() {
public void run() {
getIcmpPacket(jpcap);
}
};
new Thread(runner).start();
}

public static void main(String[] args) {
new JPing().ping("www..com");
}
}

‘叁’ java编程:如何输出网络地址 子网掩码 广播地址

importjava.net.InetAddress;
importjava.net.InterfaceAddress;
importjava.net.NetworkInterface;
importjava.net.SocketException;
importjava.net.UnknownHostException;
importjava.util.List;
publicclassTest{
publicstaticvoidmain(String[]args)throwsUnknownHostException,SocketException{
InetAddressaddress=InetAddress.getLocalHost();
System.out.println(address.getHostAddress());//输出IP地址
NetworkInterfacenetInterface=NetworkInterface.getByInetAddress(address);
if(!netInterface.isLoopback()&&netInterface.isUp()){
List<InterfaceAddress>interfaceAddresses=netInterface.getInterfaceAddresses();
for(:interfaceAddresses){
System.out.println(interfaceAddress.getNetworkPrefixLength());//输出子网掩码长度,24表示掩码255.255.255.0
if(interfaceAddress.getBroadcast()!=null){
System.out.println(interfaceAddress.getBroadcast().getHostAddress());//输出广播地址
}
}
}
}
}

‘肆’ 关于java的一些问题~

我把我的代码借鉴给你..不知道能不能够帮助你..!!!自己原创的
UDPServer.java:
import java.net.*;
import java.util.*;
public class UDPServer extends Thread {
private static final int PORT=10000 ;

private static final int DATA_LEN=2046 ;

private byte []buff =new byte[DATA_LEN];

UDPClient.java:

import java.net.*;
import java.util.*;
public class UDPClient extends Thread {
private static final int PORT=10000 ;

private static final int DATA_LEN=2046 ;

private byte []buff =new byte[DATA_LEN];

private DatagramSocket socket ;

private DatagramPacket inpacket =new DatagramPacket(buff,buff.length);

private DatagramPacket outpacket ;

public void run() {
int i =0;
try{
socket=new DatagramSocket();
outpacket =new DatagramPacket(new byte[0] ,0,
InetAddress.getByName("127.0.0.1"),PORT);
Scanner sc =new Scanner(System.in);
while(sc.hasNextLine()){
byte [] buff1 =sc.nextLine().getBytes();
outpacket.setData(buff1);
socket.send(outpacket);
socket.receive(inpacket);
System.out.println(new String(buff,0,inpacket.getLength()));
}
}catch(Exception e){
e.printStackTrace();
}
}

public static void main(String []args){
new UDPClient().start();
}

/*public UDPServer (DatagramSocket socket ,DatagramPacket inpacket,
DatagramPacket outpacket) {
this.socket = socket ;
this.inpacket = inpacket ;
this.outpacket = outpacket ;
}*/
};

MulticastSocketTest.java:
import java.awt.*;
import java.net.*;
import java.io.*;
import java.util.*;

//让该类实现Runnable接口,该类的实例可作为线程的target
public class MulticastSocketTest implements Runnable
{
//使用常量作为本程序的多点广播IP地址
private static final String BROADCAST_IP
= "230.0.0.1";
//使用常量作为本程序的多点广播目的的端口
public static final int BROADCAST_PORT = 30000;
//定义每个数据报的最大大小为4K
private static final int DATA_LEN = 4096;

//定义本程序的MulticastSocket实例
private MulticastSocket socket = null;
private InetAddress broadcastAddress = null;
private Scanner scan = null;
//定义接收网络数据的字节数组
byte[] inBuff = new byte[DATA_LEN];
//以指定字节数组创建准备接受数据的DatagramPacket对象
private DatagramPacket inPacket =
new DatagramPacket(inBuff , inBuff.length);
//定义一个用于发送的DatagramPacket对象
private DatagramPacket outPacket = null;
public void init()throws IOException
{
try
{
//创建用于发送、接收数据的MulticastSocket对象
//因为该MulticastSocket对象需要接收,所以有指定端口
socket = new MulticastSocket(BROADCAST_PORT);
broadcastAddress = InetAddress.getByName(BROADCAST_IP);
//将该socket加入指定的多点广播地址
socket.joinGroup(broadcastAddress);
//设置本MulticastSocket发送的数据报被回送到自身
socket.setLoopbackMode(false);
//初始化发送用的DatagramSocket,它包含一个长度为0的字节数组
outPacket = new DatagramPacket(new byte[0] , 0 ,
broadcastAddress , BROADCAST_PORT);
//启动以本实例的run()方法作为线程体的线程
new Thread(this).start();
//创建键盘输入流
scan = new Scanner(System.in);
//不断读取键盘输入
while(scan.hasNextLine())
{
//将键盘输入的一行字符串转换字节数组
byte[] buff = scan.nextLine().getBytes();
//设置发送用的DatagramPacket里的字节数据
outPacket.setData(buff);
//发送数据报
socket.send(outPacket);
}
}
finally
{
socket.close();
}
}

public void run()
{
try
{
while(true)
{
//读取Socket中的数据,读到的数据放在inPacket所封装的字节数组里。
socket.receive(inPacket);
//打印输出从socket中读取的内容
System.out.println("聊天信息:" + new String(inBuff , 0 ,
inPacket.getLength()));
}
}
//捕捉异常
catch (IOException ex)
{
ex.printStackTrace();
try
{
if (socket != null)
{
//让该Socket离开该多点IP广播地址
socket.leaveGroup(broadcastAddress);
//关闭该Socket对象
socket.close();
}
System.exit(1);
}
catch (IOException e)
{
e.printStackTrace();
}
}
}

public static void main(String[] args)
throws IOException
{
new MulticastSocketTest().init();
}
}

private DatagramSocket socket ;

private DatagramPacket inpacket ;

private DatagramPacket outpacket ;

public void run() {
int i =0;
try{
socket=new DatagramSocket(PORT);
while(true){
inpacket=new DatagramPacket(buff,buff.length);
socket.receive(inpacket) ;
System.out.println(new String(buff,0,inpacket.getLength()));
byte [] sedData =new String("数据信息:"+i).getBytes();
outpacket =new DatagramPacket(sedData,sedData.length,inpacket.getSocketAddress());
socket.send(outpacket);
i++ ;
}
}catch(Exception e){
e.printStackTrace();
}
}

public static void main(String []args){
new UDPServer().start();
}

/*public UDPServer (DatagramSocket socket ,DatagramPacket inpacket,
DatagramPacket outpacket) {
this.socket = socket ;
this.inpacket = inpacket ;
this.outpacket = outpacket ;
}*/
};

‘伍’ 关于java UDP方面的一些问题

看你的程序好像要实现多点传输(多播组), 可以参考MulticastSocket,也是基于UDP协议的 ,可以自动广播数据到连接上的客户端,不用等待每个客户端都要复制。那样如果数据量大,客户端多就太耗资源了。

‘陆’ java里怎么发广播呀

java里怎么发广播
public void onReceive(Context context,Intent intent){
Intent intent = new Intent(context,XxxService.class);
context.startService(intent);
}
Intent intent = new Intent();
intent.setAction("...");
Context.sendBroadcast(intent);

‘柒’ 根据ip地址和子网掩码计算网段地址和广播地址,要是java代码哦

根据IPV4的规则
IP是32位的整数,掩码是网络的补码。A类地方是高8位是网络地址、B类是高16位、类推。
广播则是对应IP地址的主机地址全是255。

‘捌’ 如何注册broadcastreceiver

静态注册(在 androidManifest.xml 中 )

[html] view plain
<receiver android:name=".BroadcastReceiverDemo" >
<intent-filter>
<action android:name="com.simware.BroadcastReceiverDemo" >
</action>
</intent-filter>
</receiver>


创建一个BroadcastReceiver

[java] view plain
public class BroadcastReceiverDemo extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
String msg = intent.getStringExtra("message");
Toast.makeText(context, msg, Toast.LENGTH_LONG).show();

}

}

在onReceive方法内,可以获取随广播而来的Intent中的数据,这非常重要,就像无线电一样,包含很多有用的信息。在创建完我们的BroadcastReceiver之后,还不能够使它进入工作状态,我们需要为它注册一个指定的广播地址。没有注册广播地址的BroadcastReceiver就像一个缺少选台按钮的收音机,虽然功能俱备,但也无法收到电台的信号。在Manifest.xml文件中已经注册了BroadcastReceiver的广播地址。

<span style="font-size: 18px;"> </span><span style="font-size:18px;">Intent mIntent = new Intent("com.simware.BroadcastReceiverDemo");
mIntent.putExtra("message", showText.getText().toString());
sendBroadcast(mIntent);</span>

‘玖’ java是否支持发送UDP广播我指的不是组播

当前网络的广播地址默认的是关闭的,所以不可能。

阅读全文

与java广播地址相关的资料

热点内容
红塔银行app怎么样 浏览:562
农行app怎么开网银 浏览:649
java迭代器遍历 浏览:301
闽政通无法请求服务器是什么 浏览:48
怎么做积木解压神器 浏览:203
王者荣耀解压玩具抽奖 浏览:49
12位是由啥加密的 浏览:868
程序员编迷你世界代码 浏览:895
php取现在时间 浏览:246
单片机高吸收 浏览:427
怎么区分五代头是不是加密喷头 浏览:244
hunt测试服务器是什么意思 浏览:510
2013程序员考试 浏览:641
毕业论文是pdf 浏览:736
服务器跑网心云划算吗 浏览:471
单片机定时器计数初值的计算公式 浏览:801
win7控制台命令 浏览:567
猫咪成年app怎么升级 浏览:692
360有没有加密软件 浏览:315
清除cisco交换机配置命令 浏览:751