First version of standalone RTMP connector
This commit is contained in:
		
							parent
							
								
									06e63e438c
								
							
						
					
					
						commit
						5af9fd2674
					
				
					 1 changed files with 41 additions and 0 deletions
				
			
		
							
								
								
									
										41
									
								
								util/ddv_socket.cpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								util/ddv_socket.cpp
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,41 @@ | |||
| #include <sys/types.h> | ||||
| #include <sys/socket.h> | ||||
| #include <arpa/inet.h> | ||||
| #include <unistd.h> | ||||
| #include <stdio.h> | ||||
| #include <errno.h> | ||||
| #include <string.h> | ||||
| 
 | ||||
| 
 | ||||
| int DDV_Listen(int port){ | ||||
|   int s = socket(AF_INET, SOCK_STREAM, 0); | ||||
| 
 | ||||
|   struct sockaddr_in addr; | ||||
|   addr.sin_family = AF_INET; | ||||
|   addr.sin_port = htons(port);//port 8888
 | ||||
|   inet_pton(AF_INET, "0.0.0.0", &addr.sin_addr);//listen on all interfaces
 | ||||
|   ret = bind(sock, (sockaddr*)&addr, sizeof(addr));//bind to all interfaces, chosen port
 | ||||
|   if (ret == 0){ | ||||
|     ret = listen(sock, 100);//start listening, backlog of 100 allowed
 | ||||
|     if (ret == 0){ | ||||
|       return s; | ||||
|     }else{ | ||||
|       printf("Listen failed! Error: %s\n", strerror(errno)); | ||||
|       close(s); | ||||
|       return 0; | ||||
|     } | ||||
|   }else{ | ||||
|     printf("Binding failed! Error: %s\n", strerror(errno)); | ||||
|     close(s); | ||||
|     return 0; | ||||
|   } | ||||
| } | ||||
| 
 | ||||
| int DDV_Accept(int sock){ | ||||
|   int r = accept(sock, 0, 0); | ||||
|   if (r != -1){ | ||||
|     return fdopen(r, "r+"); | ||||
|   }else{ | ||||
|     return -1; | ||||
|   } | ||||
| } | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Thulinma
						Thulinma