Главная страница


ru.linux

 
 - RU.LINUX ---------------------------------------------------------------------
 From : alex@starmarket.ru                   2:5020/400     18 Jan 2001  23:53:34
 To : All
 Subject : Re: Клиент - Win9x. Сервер - linux.
 -------------------------------------------------------------------------------- 
 
 Alexey Truntoff <Alexey.Truntoff@p147.f993.n5020.z2.fidonet.org> wrote:
 
 AT> Greetings, All..
 
 AT>         Объясните, plz, механизм написания клиент-серверных программ по
 AT> сабжевой схеме. Скажем, сервер (linux) посылает клиенту (win95) сообщение и
 AT> клиент его выводит на экран - может кто исходник похожий кинет? Или что по
 AT> этой теме в инете посмотреть можно?
 
 AT> .... Forever yours, Shadow Joker.
 
 всё зависит от конкретной задачи..
 если у тебя клиент MySQL на лине.. а на выне какая-нить дельфёвая задачка - то у
 тебя есть уже всё готовое..
 можно через tcpd - там серверная часть - просто прога которая читает и пишет в
 STDIN ( tcpd реализует перенаправление socket в STDIN)
 а для дельфи - TPowerSock
 и всё..
 в общем - это самый простой способ чтоб клиент слал на сервер простенькие
 комманды. сервер отрабатывал их и выдавал результат.
 я таким образом повесил на один УПС два компа - на HТ стоит контроллер УПСа а
 линь под её управлением ( жяль что я админ только линя ато я сделал бы наоборот)
 в итоге - на лине простая прога :
 
 #!/usr/bin/perl
 print "WhAt YoU WhAnT?!?!\n";
 $inp = readline(*STDIN);
 chomp $inp;
 print `date`;
 if ($inp=~/rebootplease/) { print "rebooting.... \n" ;} else {print " error ...
 \n ";}   
 
 [alex@lokki alex]$ grep ups /etc/services
 ups             1024/tcp
 [alex@lokki alex]$ grep ups /etc/inetd.conf
 ups     stream  tcp     nowait  root    /usr/sbin/tcpd  /usr/sbin/ups >>
 /var/log/secure 
 
 [alex@lokki alex]$ grep ups /etc/hosts.allow
 ups: 192.168.0.1  
 
 и для винды простенький клиент
 
 // someprog.cpp : Defines the entry point for the console application.
 //
 
 #include "stdafx.h"
 #include "someprog.h"
 #include <afxsock.h>
 
 #ifdef _DEBUG
 #define new DEBUG_NEW
 #undef THIS_FILE
 static char THIS_FILE[] = __FILE__;
 #endif
 
 /////////////////////////////////////////////////////////////////////////////
 // The one and only application object
 
 CWinApp theApp;
 
 using namespace std;
 
 int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
 {
   int nRetCode = 0;
 
   // initialize MFC and print and error on failure
   if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0) ||
    !AfxSocketInit() )
   {
    // TODO: change error code to suit your needs
    cerr << _T("Fatal Error: MFC initialization failed") << endl;
    nRetCode = 1;
   }
   else
   {
    if ( argc != 2 )
    {  cerr << _T("Run: someprog <ini-file-name>") << endl;
       nRetCode = 1;
    }
    
    TCHAR strConfigFile[_MAX_PATH];
    ::GetCurrentDirectory( sizeof(strConfigFile) / sizeof(TCHAR), strConfigFile
 );
    _tcscat( strConfigFile, _T("\\") );
    _tcscat( strConfigFile, argv[1] );
 
    // Configuration parameters
    TCHAR strAddress[17] = _T("");
    UINT nPort = 0;
    TCHAR strText[65536] = _T("");  // Text buffer
 
    if ( nRetCode == 0)
    {
       // Read configuration
       ::GetPrivateProfileString( _T("main"), _T("host"), _T(""), 
        strAddress, sizeof(strAddress) / sizeof(TCHAR), strConfigFile );
       nPort = ::GetPrivateProfileInt( _T("main"), _T("port"), 0, strConfigFile
 );
       ::GetPrivateProfileString( _T("main"), _T("text"), _T(""), 
        strText, sizeof(strText) / sizeof(TCHAR), strConfigFile );
 
       if ( nPort == 0 || strAddress[0] == _T('\0') )
       {
        cerr << _T("Fatal Error: initialization file is missed or corrupted") << 
 endl;
        nRetCode = 1;
       }
    }
 
    CSocket theSocket;
       
    if ( nRetCode == 0 )
    {
       // Connect
       if ( !theSocket.Create( nPort, SOCK_DGRAM, strAddress ) )
       {
        cerr << _T("Fatal Error: connection could not been established") << endl;
        nRetCode = 1;
       }
    }
 
    if ( nRetCode == 0 )
    {
       // Send message
       if ( theSocket.Send( strText, _tcslen( strText ) * sizeof(TCHAR) ) ==
 SOCKET_ERROR )
       {
        cerr << _T("Error has occured while message was being sent") << endl;
        nRetCode = 1;
       }
       else
        cout << _T("Message has been sent successfully") << endl;
       theSocket.Close();
    }
   }
 
   return nRetCode;
 }
                                                                                   
                                                                                   
                                                                                   
                                                    }                            
 
 -- 
 
 Отправлено через сервер Talk.Ru - http://www.talk.ru
 --- ifmail v.2.15dev5
  * Origin: Digital Commerce (2:5020/400)
 
 

Вернуться к списку тем, сортированных по: возрастание даты  уменьшение даты  тема  автор 

 Тема:    Автор:    Дата:  
 Клиент - Win9x. Сервер - linux.   Alexey Truntoff   18 Jan 2001 17:54:06 
 Re: Клиент - Win9x. Сервер - linux.   Igor Belokopytov   18 Jan 2001 20:37:49 
 Re: Клиент - Win9x. Сервер - linux.   alex@starmarket.ru   18 Jan 2001 23:53:34 
Архивное /ru.linux/20999a95e09b2.html, оценка 2 из 5, голосов 10
Яндекс.Метрика
Valid HTML 4.01 Transitional