资源简介
JAVA实现的流服务(直播,点播),JAVA实现的RTSP协议,可以实现与网络客户端的交互
代码片段和文件信息
package main.java.rvsup.controller;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.net.ServerSocket;
import java.net.Socket;
import java.security.MessageDigest;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import java.util.UUID;
/**
* @author lenovo on 2017/12/1.
* @version 1.0
*/
public class RtspServer {
private static final String CRLF = “\r\n“;
private static final String LOCAL_IP = “192.168.0.216“;
private static final String password = “zhidu!2#4“;
private static AvsServer avsServer = new AvsServer();
private static String client_port = null;
/**
* Socket服务端
*/
public static void main(String[] args) {
Socket socket = null;
InputStream inputStream = null;
InputStreamReader inputStreamReader = null;
BufferedReader bufferedReader = null;
OutputStream outputStream = null;
PrintWriter printWriter = null;
try {
ServerSocket serverSocket=new ServerSocket(554);
System.out.println(“服务端已启动,等待客户端连接..“);
socket=serverSocket.accept();//侦听并接受到此套接字的连接返回一个Socket对象
//根据输入输出流和客户端连接
inputStream=socket.getInputStream();//得到一个输入流,接收客户端传递的信息
inputStreamReader=new InputStreamReader(inputStream);//提高效率,将字节流转为字符流
bufferedReader=new BufferedReader(inputStreamReader);//加入缓冲区
outputStream=socket.getOutputStream();//获取一个输出流,向客户端发送信息
printWriter=new PrintWriter(outputStream);//将输出流包装成打印流
String temp;
String info;
while(true){
temp = null;
info = ““;
//将缓冲区中的字符流组成字符串
//这个循环用((temp = bufferedReader.readLine()) != null)跳不出来,因为socket没有断开
while(!(temp=bufferedReader.readLine()).equals(““)){
info+=temp;
}
System.out.println(“服务端接收到客户端信息:“+info+“当前客户端ip和port为:“+socket.getInetAddress().getHostAddress()+“ “+socket.getPort());
if(info.startsWith(“DESCRIBE“)){
if(!info.contains(“Authorization“)){
//sescribe请求第一步,无鉴权信息,回复401
authorizationFailed(info printWriter);
}else{
if(authorization(info “DESCRIBE“)){
//describe请求鉴权成功,回复200OK
describeAuthorizationSuccess(info printWriter);
}else{
//鉴权失败,回复401
authorizationFailed(info printWriter);
}
}
}else if(info.startsWith(“SETUP“)){
if(auth
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 13448 2017-12-18 15:45 JRTSPServer\RtspServer.java
目录 0 2018-11-16 10:31 JRTSPServer\
评论
共有 条评论