Advertisement

automatic detect

Started by October 26, 2003 12:42 PM
1 comment, last by galadril 21 years, 3 months ago
Hi,everyone I have coded game server and client,it work fine I defined server address string for client program and use gethostbyname(...) to access server info that''s mean I have to put server program on a machine (Like if I run server program on Machine name A ,I have to change servername string in client program to A ...if I run server on Machine B ,I have to edit servername string in client program to B again.) but now I try to change some detail of server that I try to make it dynamic.I mean client can detect what is server address without edit servername string everytime. my problem is I don''t know how to do. First I try srver=getservbyport(htons(port),NULL) to get server port and then use host_entry = gethostbyname(srver->s_name) which struct servent *srver; and struct hostent *host_entry; but it fail. Winsock report error 11004. Anyone plese,give me some comment Thanks
I know I was misunderstood with getservbyport function
the return value is struct servent
struct servent {
char *s_name; /* official service name */
char **s_aliases; /* alias list */
int s_port; /* port number */
char *s_proto; /* protocol to use */
}
I thought that s_name is host name but it''s not.
s_name is service name so what next should I thinking about??
Hmmm....


Advertisement
you could have the server post it''s IP somewhere that doesn''t change (i.e. a website or something), so the client just has to request the server''s current location from there, and then connect.
--- krez ([email="krez_AT_optonline_DOT_net"]krez_AT_optonline_DOT_net[/email])

This topic is closed to new replies.

Advertisement