一个消息提示托盘程序的开发历程(采用socket技术,附源代码)二---服务端源代码[1]

[入库:2005年8月19日] [更新:2007年3月24日]

本文简介:选择自 lcllcl987 的 blog

消息提示工具源码:
服务端:
msg.h
/*
 * create date: 2004-12-01 
 * create by: 李春雷
 * purpose: 协议用自定义消息结构:
 *          messageinfo:任务消息
 *          msgtype消息头:0xa登陆成功,0xb登陆失败,0xc工作消息,0xd任务结束标识
 *          logininfo:登陆消息
 */

//------------------------------------------------------------------------------

        struct messageinfo{               //消息结构
           int  msgtype;                  //消息头:0xa登陆成功,0xb登陆失败,0xc工作消息,0xd任务结束标识
           char  messageid[10];           //任务序号
           char usrcode[10];              //用户帐号
           //char tastname[50];             //任务名称
           char tastname[200];             //任务名称
           char creattime[20];            //时间
        };

         struct logininfo{          //登陆信息
                char pwd[20];       //用户密码
                char userid[30];    //用户id
        };
//------------------------------------------------------------------------------


unit1.cpp
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop
#include "unit1.h"
#include "unit2.h"
#include "msg.h"
#include <inifiles.hpp>
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
tform1 *form1;
string myprovider;//数据库连接字符
int port;     //端口;
//---------------------------------------------------------------------------
__fastcall tform1::tform1(tcomponent* owner)
        : tform(owner)
{
                    isserver=false;
                    server="localhost";
}
//---------------------------------------------------------------------------


void __fastcall tform1::formcreate(tobject *sender)
{
//
char dir[max_path];
//----获取运行程序的目录开始
char *tfile = "/config.ini";
//将程序现在目录所在输入此字符数组
::getcurrentdirectory(max_path,dir);
//将现在目录加上指定文件名
strcat(dir,tfile);
//----获取运行程序的目录结束
tinifile  *ini = new tinifile(dir);
try
{
  myprovider = ini->readstring("servercfg","provider","provider=oraoledb.oracle.1;password=pwsc;persist security info=true;user id=developer;data source=dl;extended properties=""");
  port = ini->readinteger("servercfg","port",1555);
}
catch(...)
{
  messagebox(application->handle,"读取配置文件config.ini失败!","信息提示!",mb_ok+mb_iconinformation+mb_systemmodal);
  delete ini;
}
delete ini;
   adoconnection1->connectionstring = myprovider;
   adoconnection1->loginprompt = false;
   try
   {
      adoconnection1->open();
   }
   catch(...)
   {
      showmessage("无法连接数据库");
      return;
   }

    btndisconnect->enabled=false;
}
//---------------------------------------------------------------------------

void __fastcall tform1::btnlistenclick(tobject *sender)
{
//程序运行后,如果用户按下"监听"钮,
//则将该程序设为服务器端,
//这时应将tserversocket的active属性设为true,
//使服务器自动进入监听状态。
    serversocket1->port = port;
    serversocket1->active=true;
    statusbar1->simpletext="正在监听...";

本文关键:一个消息提示托盘程序的开发历程(采用socket技术,附源代码)二---服务端源代码
  相关方案
Google
 

本站最佳浏览方式为 分辨率 1024x768 IE 6.0(或更高版本的 IE浏览器)

go top