|
我在构建一个简单的分布式系统
主进程可以在任何一个节点上启动,它向本网段(假设192.168.1.0/24)所有的机器发送广播数据包,即向192.168.1.255发送,来启动所有可以启动的从进程。
我写了这样一个xinetd配置文件。但试了试,从进程没能被启动,不知哪点没考虑周到。请大虾指教
[code:1]
service rcatd
{
disable = no
port = 5000
socket_type = dgram
protocol = udp
wait = yes
user = andy
only_from = 192.168.1.0/24
server = /home/andy/cluster/bin/slave
}
[/code:1]
如何检查xinetd所监听的端口?我netstat -atn看不到5000端口。
这里附加上主进程发送广播数据包的代码段,为简洁起见,部分变量声明在此简略
[code:1]
char *p;
unsigned char bcaddr[4] = {0xC0, 0xA8, 0x01, 0xFF}; /*192.168.1.255 */
/*
** establish a UDP broadcast socket
*/
b_fd = socket (AF_INET, SOCK_DGRAM, 0);
// memset ((char *) &broadcast, 0, len);
bzero(&broadcast, sizeof(broadcast));
broadcast.sin_family = AF_INET;
broadcast.sin_port = htons (BROADCAST);
// memcpy(&broadcast.sin_addr, bcaddr, 4);
broadcast.sin_addr.s_addr = inet_addr("224.0.0.1");
setsockopt (b_fd, SOL_SOCKET, SO_BROADCAST, (char *) &opt, sizeof (opt));
/ *
* start up all remote slave services
*/
gethostname (hostname, sizeof (hostname));
if ((p = strchr (hostname, '.')) != NULL)
{
*p = '\0'; /* trunc .domainname */
}
sendto (b_fd, hostname, strlen (hostname) + 1, 0,
(struct sockaddr *) &broadcast, len);
close (b_fd);
[/code:1] |
|