Changeset 9453 in ntrip
- Timestamp:
- Jun 7, 2021, 2:36:06 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ntripserver/ntripserver.c
r9452 r9453 138 138 static sockettype gps_socket = INVALID_SOCKET; 139 139 static sockettype socket_tcp = INVALID_SOCKET; 140 static sockettype local_socket_tcp = INVALID_SOCKET; 140 141 static sockettype socket_udp = INVALID_SOCKET; 141 142 #ifndef WINDOWSVERSION … … 897 898 break; 898 899 } 900 901 if (outputmode == TCPIP) { 902 // Forcefully attaching socket to the local port 903 int opt = 1; 904 if (setsockopt(socket_tcp, SOL_SOCKET, SO_REUSEADDR | SO_REUSEPORT, 905 &opt, sizeof(opt))) { 906 perror("setsockopt"); 907 break; 908 } 909 } 899 910 memset((char*) &caster, 0x00, sizeof(caster)); 900 911 memcpy(&caster.sin_addr, he->h_addr, (size_t)he->h_length); … … 910 921 outputmode == RTSP ? "rtsp" : "tcpip"); 911 922 912 if (connect(socket_tcp, (struct sockaddr*) &caster, sizeof(caster)) < 0) { 913 fprintf(stderr, "WARNING: can't connect output to %s at port %d", 914 inet_ntoa(caster.sin_addr), outport); 915 perror(" "); 916 break; 923 if (outputmode == TCPIP) { 924 // Forcefully attaching socket to the local port 925 if (bind(socket_tcp, (struct sockaddr *)&caster, sizeof(caster)) < 0) { 926 perror("bind failed"); 927 break; 928 } 929 if (listen(socket_tcp, 3) < 0) { 930 perror("listen"); 931 break; 932 } 933 int addrlen = sizeof(caster); 934 if ((local_socket_tcp = accept(socket_tcp, (struct sockaddr *)&caster, 935 (socklen_t*)&addrlen)) < 0) { 936 perror("accept"); 937 break;; 938 } 939 } 940 else { 941 if (connect(socket_tcp, (struct sockaddr*) &caster, sizeof(caster)) < 0) { 942 fprintf(stderr, "WARNING: can't connect output to %s at port %d", 943 inet_ntoa(caster.sin_addr), outport); 944 break; 945 } 917 946 } 918 947 … … 1308 1337 case TCPIP: 1309 1338 fallback = 0; 1310 send_receive_loop( socket_tcp, outputmode, NULL, 0, 0, chunkymode);1339 send_receive_loop(local_socket_tcp, outputmode, NULL, 0, 0, chunkymode); 1311 1340 input_init = output_init = 0; 1312 1341 break;
Note:
See TracChangeset
for help on using the changeset viewer.