Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 238
  • Last Modified:

Connect to a server

How do I connect to an X400 server? My application needs to connect to the server - check if it is up and then disconnect.
0
JennyP
Asked:
JennyP
  • 6
  • 6
  • 2
1 Solution
 
adamretterCommented:
Firstly what protocols are running on your network, what protocols does your x400 server support and what platform are you programming your checking application on.

If TCP/IP is available then you could simply create a small c++ program that does an ICMP ping off of the x400 server to tell if it is switched on and responding to network requests.
0
 
JennyPAuthor Commented:
TCP/IP is available. I will need to check if the server is up under 2 conditions:
1. ISDN modem dial up
2. over a WAN
How would I do a ping? Simple C++ code that I can include in my program will be great. I will increase points if required.

0
 
adamretterCommented:
Two Options
===========

1.)
You need to Use RAW sockets in Windows as far as I can understand.
These are only available under windows 2000/xp and must be executed by someone with Administrator privelledges.

Would this be of any use?

2.) Redirect C++ Standard I/O pipes so that you can simply call ping.exe the dos cmd and use that.


0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
lsmgmsCommented:
Hi,

How about makeing SNMP request to query system up time?  Assume you can get the community name.
0
 
JennyPAuthor Commented:
I don't think RAW sockets will be of use 'cos this app will run of various OS Win 9x, Win 2000, etc.

Don't have the community name so I am not sure a SNMP request will work.

How would I redirect Standard I/O pipes? How will I be able to intepret the success or fail from the dos ping command ? I know it returns a reply...but how can I read that from my C++ app?

0
 
lsmgmsCommented:
Please look at this:

http://support.microsoft.com/default.aspx?scid=kb;EN-US;q190351

However I myself have not tried before.  Are you sure you want to do this because it is very urgly, for me.

You do not need to have full access right community name, just read-only is good enough.
0
 
JennyPAuthor Commented:
I am not sure I want to do that. What would you suggest as an alternative? I am looking for a simple way to connect to an X400 server (I have the IP address and port) to check if it is up and running. The function must return a value for my app to interpret if the server is up or down.
0
 
lsmgmsCommented:
>> (I have the IP address and port)

Is it a TCP port? Can you just open a socket and then connect to that IP and port and immediately close it? If socket is opened successfully, we can confirm that server is on.
0
 
JennyPAuthor Commented:
Yes, it is TCP/IP. What would I use CSocket or similar ? And how ? Excuse my ignorance.
0
 
lsmgmsCommented:
- Open a blocking socket
- Call Connect()
- Check return value whether success or not.
- Close the socket.

Either CSocket or WINSOCK API will do.  
0
 
JennyPAuthor Commented:
Do we not need to pass any username & password?
0
 
lsmgmsCommented:
I think you are new to socket, try the example below.  Replace params in IsAlive("127.0.0.1",23) with your server and port.  It does not need any username, so long as the firewall allows you to do that.  I hope this has enough info for you to solve the problem.




#include <windows.h>
#include <winsock.h>
#include <stdio.h>

int IsAlive(char *szServer, short nPort)
{
     int alive =0;

     SOCKET     theSocket;

     theSocket = socket(AF_INET,                    // Address family
                            SOCK_STREAM,               // Socket type
                            IPPROTO_TCP);          // Protocol
     if (theSocket == INVALID_SOCKET)
     {
          printf("Open socket error %ld", WSAGetLastError());
          return 0;
     }

     //
     // Fill in the address structure
     //
     SOCKADDR_IN saServer;

     saServer.sin_family = AF_INET;
     saServer.sin_addr.S_un.S_addr  = inet_addr(szServer);
     saServer.sin_port = htons(nPort);    

     //
     // connect to the server
     //
     if( connect(theSocket,                    
                       (struct sockaddr*)&saServer,    
                       sizeof(struct sockaddr)) != SOCKET_ERROR      
                          )
          alive = 1;
     else
          printf("Connect error %ld", WSAGetLastError());

     closesocket(theSocket);

     return alive;
}


int main(int argc, char* argv[])
{
     WORD wVersionRequested = MAKEWORD(1,1);
     WSADATA wsaData;
     int nRet;


     nRet = WSAStartup(wVersionRequested, &wsaData);
     if (wsaData.wVersion != wVersionRequested)
     {    
          fprintf(stderr,"\n Wrong version\n");
          return 0;
     }


     //
     // Go do the stuff a stream client does
     //
     if( IsAlive("127.0.0.1",23))
          printf("Alive");
     else
          printf("NOT Alive");

     
     //
     // Release WinSock
     //
     WSACleanup();


     return 1;
}
0
 
lsmgmsCommented:
Forgot to mention, you have to include Ws2_32.lib library to your project.
0
 
JennyPAuthor Commented:
This was great. thanks for the help !
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 6
  • 6
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now