How to scan for a port in the lan.
-
This might be a very trivial question for most of you. I want to know how to write a program in vc++ for scanning a particular port on the lan. I have written a chat program, I want that whenever a user starts the client, it scans the network and finds the ip for connecting, if no server is found it will become a server. Most messengers do the same thing I suppose. Thanks in advance. I dream so I do.
-
This might be a very trivial question for most of you. I want to know how to write a program in vc++ for scanning a particular port on the lan. I have written a chat program, I want that whenever a user starts the client, it scans the network and finds the ip for connecting, if no server is found it will become a server. Most messengers do the same thing I suppose. Thanks in advance. I dream so I do.
Hi I have a suggest,I think it is better to use othere way to find server. If you wana to use your messanger on a LAN you can use broadcast messages. when a client want to find server Send a BC message on the network if server peresent answer it by sending message contain its IP & other information and if isn't present the client can work as a server after some try and listen for clients BC message. Iman Ghasrfakhri
-
Hi I have a suggest,I think it is better to use othere way to find server. If you wana to use your messanger on a LAN you can use broadcast messages. when a client want to find server Send a BC message on the network if server peresent answer it by sending message contain its IP & other information and if isn't present the client can work as a server after some try and listen for clients BC message. Iman Ghasrfakhri
-
Yes, that's exactly what I want to do, but I donot know how to implement. Could you please help me with code. Thanks. I dream so I do.
Hi in this code I listen a socket to receive server's response and then Send BC message to the network (this is a client action)
// m_LSocket is a Class member & its type is CAsyncSocket * m_LSocket->Create(1000); m_LSocket->Listen(); CAsyncSocket s; s.Create(334400,SOCK_DGRAM); BOOL bOptVal = TRUE; s.SetSockOpt(SO_BROADCAST,(char*)&bOptVal,sizeof(BOOL)); char buf[256]; CString Address("255.255.255.255"); // broadcast IP unsigned int port = 1000; // Port No. strcpy(buf,"Requesting Connection"); // Message s.SendTo(buf,256,port); // Sending
On the server side you most listen a Datagram socke (SOCK_DGRAM), and wait to receive a connection request. Is it enough.;) Iman Ghasrfakhri -
Hi in this code I listen a socket to receive server's response and then Send BC message to the network (this is a client action)
// m_LSocket is a Class member & its type is CAsyncSocket * m_LSocket->Create(1000); m_LSocket->Listen(); CAsyncSocket s; s.Create(334400,SOCK_DGRAM); BOOL bOptVal = TRUE; s.SetSockOpt(SO_BROADCAST,(char*)&bOptVal,sizeof(BOOL)); char buf[256]; CString Address("255.255.255.255"); // broadcast IP unsigned int port = 1000; // Port No. strcpy(buf,"Requesting Connection"); // Message s.SendTo(buf,256,port); // Sending
On the server side you most listen a Datagram socke (SOCK_DGRAM), and wait to receive a connection request. Is it enough.;) Iman Ghasrfakhri -
Hi in this code I listen a socket to receive server's response and then Send BC message to the network (this is a client action)
// m_LSocket is a Class member & its type is CAsyncSocket * m_LSocket->Create(1000); m_LSocket->Listen(); CAsyncSocket s; s.Create(334400,SOCK_DGRAM); BOOL bOptVal = TRUE; s.SetSockOpt(SO_BROADCAST,(char*)&bOptVal,sizeof(BOOL)); char buf[256]; CString Address("255.255.255.255"); // broadcast IP unsigned int port = 1000; // Port No. strcpy(buf,"Requesting Connection"); // Message s.SendTo(buf,256,port); // Sending
On the server side you most listen a Datagram socke (SOCK_DGRAM), and wait to receive a connection request. Is it enough.;) Iman Ghasrfakhri