好久沒寫了,換工作之后,在這家游戲公司,最先了解到的就是red5,學習到了如何搭建red5應用程序,貼出來分享一下。(本來上周就可以貼出來的,工作太忙了,^ _ ^)
安裝完red5,在默認的情況下,red5將所有的應用程序存放在根目錄的“webapp”目錄下面。因此在創(chuàng)建一個新的應用程序之前,首先需要在這個目錄中創(chuàng)建一個子目錄。習慣上這個子目錄的名字應該和馬上創(chuàng)建的應用程序的名字是一樣的。
在red5的安裝目錄(\doc\templates\ )下找到myapp文件夾,把它整個拷貝到red5安裝目錄的webapps文件夾下,然后重命名為“tempapp”(可根據(jù)自己的需要自己改名)。這個文件夾中包含的是一個red5端應用程序配置的模板,對這個模板進行簡單的修改,就可以將我們編寫的應用程序正常的運行在red5服務器上。具體修改方法如下:
1、修改pet\WEB-INF下的四個文件,只要看到“myapp”就將其替換成“tempapp”。
2、修改red5-web.properties文件中的webapp.virtualHosts為*,localhost, 127.0.0.1。
代碼如下:
1
webapp.contextPath=/tempapp
2
webapp.virtualHosts=*,localhost, 127.0.0.1

2

3、修改red5-web.xml中的class="the.path.to.my.Application"為class="org.red5.server.adapter.ApplicationAdapter"。
代碼如下:
1
<?xml version="1.0" encoding="UTF-8"?>
2
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
3
<beans>
4
5
<bean id="placeholderConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
6
<property name="location" value="/WEB-INF/red5-web.properties" />
7
</bean>
8
9
<bean id="web.context" class="org.red5.server.Context"
10
autowire="byType" />
11
12
<bean id="web.scope" class="org.red5.server.WebScope"
13
init-method="register">
14
<property name="server" ref="red5.server" />
15
<property name="parent" ref="global.scope" />
16
<property name="context" ref="web.context" />
17
<property name="handler" ref="web.handler" />
18
<property name="contextPath" value="${webapp.contextPath}" />
19
<property name="virtualHosts" value="${webapp.virtualHosts}" />
20
</bean>
21
22
<bean id="web.handler"
23
class="org.red5.server.adapter.ApplicationAdapter"
24
singleton="true" />
25
26
</beans>
27

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

4、web.xml文件中的代碼也貼出來:
1
<?xml version="1.0" encoding="ISO-8859-1"?>
2
<web-app
3
xmlns="http://java.sun.com/xml/ns/j2ee"
4
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
6
version="2.4">
7
8
<display-name>My sample Red5 application</display-name>
9
10
<context-param>
11
<param-name>globalScope</param-name>
12
<param-value>default</param-value>
13
</context-param>
14
15
<context-param>
16
<param-name>contextConfigLocation</param-name>
17
<param-value>/WEB-INF/red5-*.xml</param-value>
18
</context-param>
19
20
<context-param>
21
<param-name>locatorFactorySelector</param-name>
22
<param-value>red5.xml</param-value>
23
</context-param>
24
25
<context-param>
26
<param-name>parentContextKey</param-name>
27
<param-value>default.context</param-value>
28
</context-param>
29
30
<context-param>
31
<param-name>log4jConfigLocation</param-name>
32
<param-value>/WEB-INF/log4j.properties</param-value>
33
</context-param>
34
35
<context-param>
36
<param-name>webAppRootKey</param-name>
37
<param-value>/templates_myapp</param-value>
38
</context-param>
39
<!--
40
<listener>
41
<listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
42
</listener>
43
44
<listener>
45
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
46
</listener>
47
-->
48
<!-- remove the following servlet tags if you want to disable remoting for this application -->
49
<servlet>
50
<servlet-name>gateway</servlet-name>
51
<servlet-class>org.red5.server.net.servlet.AMFGatewayServlet</servlet-class>
52
</servlet>
53
54
<servlet-mapping>
55
<servlet-name>gateway</servlet-name>
56
<url-pattern>/gateway</url-pattern>
57
</servlet-mapping>
58
59
<security-constraint>
60
<web-resource-collection>
61
<web-resource-name>Forbidden</web-resource-name>
62
<url-pattern>/streams/*</url-pattern>
63
</web-resource-collection>
64
<auth-constraint/>
65
</security-constraint>
66
67
</web-app>
68

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

注意:我用的是Red5-0.8.0-RC2,在啟動red5時,會報錯,注釋其中的兩個監(jiān)聽就沒有問題了!本人做的是java,只提供red5服務器端的代碼,呵呵,因為flex不會,所以有興趣的朋友請參照:
http://seasontop.blog.hexun.com/28885448_d.html
這樣一個red5服務器就算配置完了,祝你們好運~!