Connect to all LAN servers
-
i want to connect my application to all servers on LAN using TCP sockets.
UINT CD1MessageDlg::ScanLAN(LPVOID pParam)
{
unsigned int tf0, tf1, tf2, tf3;
CString tip = "";CD1MessageDlg \*t; t=(CD1MessageDlg\*)pParam; BOOL x = 1; // Loop for scanning LAN for (tf0 = 192; tf0 <= 192; tf0++) { for (tf1 = 168; tf1 <= 168; tf1++) { for (tf2 = 109; tf2 <= 117; tf2++) { for (tf3 = 1; tf3 <= 255; tf3++) { tip.Format("%u.%u.%u.%u", tf0, tf1, tf2, tf3); t->m\_sConnectSocket.Connect(tip, 50000);
//.
//.
//.
// I will detach the socket and pass to seperate thread after it finds a server on LAN
//this line is not working even if i set my ip to 192.168.109.2
//t->m_sConnectSocket.Connect(tip, 50000);
}
// reset tf3 to default value
tf3 = 0;
}
// reset tf2 to default value
tf2 = 109;
}
// reset tf1 to default value
tf1 = 168;
}
return 0;
}one more ques. can i reuse the same socket again and again for finding server as i'm doing in my this code.
Future Lies in Present. Manmohan Bishnoi
-
i want to connect my application to all servers on LAN using TCP sockets.
UINT CD1MessageDlg::ScanLAN(LPVOID pParam)
{
unsigned int tf0, tf1, tf2, tf3;
CString tip = "";CD1MessageDlg \*t; t=(CD1MessageDlg\*)pParam; BOOL x = 1; // Loop for scanning LAN for (tf0 = 192; tf0 <= 192; tf0++) { for (tf1 = 168; tf1 <= 168; tf1++) { for (tf2 = 109; tf2 <= 117; tf2++) { for (tf3 = 1; tf3 <= 255; tf3++) { tip.Format("%u.%u.%u.%u", tf0, tf1, tf2, tf3); t->m\_sConnectSocket.Connect(tip, 50000);
//.
//.
//.
// I will detach the socket and pass to seperate thread after it finds a server on LAN
//this line is not working even if i set my ip to 192.168.109.2
//t->m_sConnectSocket.Connect(tip, 50000);
}
// reset tf3 to default value
tf3 = 0;
}
// reset tf2 to default value
tf2 = 109;
}
// reset tf1 to default value
tf1 = 168;
}
return 0;
}one more ques. can i reuse the same socket again and again for finding server as i'm doing in my this code.
Future Lies in Present. Manmohan Bishnoi
you probably can - but if you fail to connect your socket will 'block' for the timeout, so you may want to use a socket pool furthermore,
Manmohan29 wrote:
for (tf0 = 192; tf0 <= 192; tf0++) { for (tf1 = 168; tf1 <= 168; tf1++) {
loops are redundant, and in
Manmohan29 wrote:
tip.Format("%u.%u.%u.%u", tf0, tf1, tf2, tf3);
you're not specifying a port - so what do you hope to connect to ?
-
you probably can - but if you fail to connect your socket will 'block' for the timeout, so you may want to use a socket pool furthermore,
Manmohan29 wrote:
for (tf0 = 192; tf0 <= 192; tf0++) { for (tf1 = 168; tf1 <= 168; tf1++) {
loops are redundant, and in
Manmohan29 wrote:
tip.Format("%u.%u.%u.%u", tf0, tf1, tf2, tf3);
you're not specifying a port - so what do you hope to connect to ?
Garth J Lancaster wrote:
for (tf0 = 192; tf0 <= 192; tf0++) { for (tf1 = 168; tf1 <= 168; tf1++) { loops are redundant
this code is for only testing purpose. i will modify my function to take ip address range from user.
Garth J Lancaster wrote:
tip.Format("%u.%u.%u.%u", tf0, tf1, tf2, tf3); you're not specifying a port - so what do you hope to connect to ?
i'm specifying port 50000
t->m_sConnectSocket.Connect(tip, 50000);
Future Lies in Present. Manmohan Bishnoi
-
Garth J Lancaster wrote:
for (tf0 = 192; tf0 <= 192; tf0++) { for (tf1 = 168; tf1 <= 168; tf1++) { loops are redundant
this code is for only testing purpose. i will modify my function to take ip address range from user.
Garth J Lancaster wrote:
tip.Format("%u.%u.%u.%u", tf0, tf1, tf2, tf3); you're not specifying a port - so what do you hope to connect to ?
i'm specifying port 50000
t->m_sConnectSocket.Connect(tip, 50000);
Future Lies in Present. Manmohan Bishnoi
Manmohan29 wrote:
i'm specifying port 50000
my mistake - I had forgotten the Connect() parameters - I was thinking you were specifying the timeout .. in which case, as I said, if you get a connect fail, you'll have to wait for the timeout for the socket to become available again I think ... 'g'
-
i want to connect my application to all servers on LAN using TCP sockets.
UINT CD1MessageDlg::ScanLAN(LPVOID pParam)
{
unsigned int tf0, tf1, tf2, tf3;
CString tip = "";CD1MessageDlg \*t; t=(CD1MessageDlg\*)pParam; BOOL x = 1; // Loop for scanning LAN for (tf0 = 192; tf0 <= 192; tf0++) { for (tf1 = 168; tf1 <= 168; tf1++) { for (tf2 = 109; tf2 <= 117; tf2++) { for (tf3 = 1; tf3 <= 255; tf3++) { tip.Format("%u.%u.%u.%u", tf0, tf1, tf2, tf3); t->m\_sConnectSocket.Connect(tip, 50000);
//.
//.
//.
// I will detach the socket and pass to seperate thread after it finds a server on LAN
//this line is not working even if i set my ip to 192.168.109.2
//t->m_sConnectSocket.Connect(tip, 50000);
}
// reset tf3 to default value
tf3 = 0;
}
// reset tf2 to default value
tf2 = 109;
}
// reset tf1 to default value
tf1 = 168;
}
return 0;
}one more ques. can i reuse the same socket again and again for finding server as i'm doing in my this code.
Future Lies in Present. Manmohan Bishnoi
Consider the possibility to use "multicast" http://en.wikipedia.org/wiki/IP_multicast[^]. Check with your network administrator if this is possible in you environment, before spreading a potentially huge number of independent identical flows, or you may risk to sit down your network.
2 bugs found. > recompile ... 65534 bugs found. :doh:
-
Consider the possibility to use "multicast" http://en.wikipedia.org/wiki/IP_multicast[^]. Check with your network administrator if this is possible in you environment, before spreading a potentially huge number of independent identical flows, or you may risk to sit down your network.
2 bugs found. > recompile ... 65534 bugs found. :doh:
emilio_grv wrote:
Check with your network administrator if this is possible in you environment
It is not possible in our college network as told by our N/W Admin. Thanx. :)
Future Lies in Present. Manmohan Bishnoi