導航:首頁 > 編程語言 > 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還款怎麼登錄不上去了 瀏覽:663
鄭州雲伺服器託管 瀏覽:720
伺服器地址跟蹤 瀏覽:978
免費google雲伺服器 瀏覽:516
摘譯和編譯的英文 瀏覽:359
熱泵壓縮機選型 瀏覽:121
op手機微信加密如何解除 瀏覽:386
如何在王牌戰爭找到高爆率伺服器 瀏覽:13
江浙小學語文輔導課用什麼APP 瀏覽:99
新夢幻大陸伺服器地址 瀏覽:241
網吧伺服器怎麼更換壁紙 瀏覽:530
linux命令方法 瀏覽:332
linux下載freetype 瀏覽:123
程序員入駐平台 瀏覽:327
程序員大戰外掛 瀏覽:745
html實例教程pdf 瀏覽:157
linux命令開放所有許可權 瀏覽:575
30歲能學會編程 瀏覽:737
小火箭的伺服器是什麼 瀏覽:967
cad查信息命令 瀏覽:402