找回密码
 用户注册

QQ登录

只需一步,快速开始

查看: 7332|回复: 3

老出现"WSA startup not initialized"错误是怎么回事啊

[复制链接]
发表于 2008-4-3 23:57:47 | 显示全部楼层 |阅读模式
#include <ace/OS_main.h>
#include
<ace/ACE.h>
#include
<ace/Log_Msg.h>
#include
<ace/SOCK_Acceptor.h>
#include
<ctime>

#pragma comment(lib,"ACED.lib")

int main(int argc, char
*argv[])
{
    ACE_INET_Addr addr(
1500);
    ACE_SOCK_Acceptor server;
    ACE_SOCK_Stream stream;

   
if(server.open(addr)==-1)
    {
        ACE_DEBUG ((LM_DEBUG,
            ACE_TEXT (
"(%P|%t) %p\n"),
            ACE_TEXT (
"bind failed")));
        
return
1;
    }

   
char msg[15];

   
while(server.accept(stream)!=-1)
    {
        ACE_INET_Addr raddr;
        stream.get_remote_addr(raddr);
        ACE_DEBUG ((LM_DEBUG,ACE_TEXT (
"(%P|%t) connect:%s %d\n"),raddr.get_host_addr(),raddr.get_port_number()));

        
//get current time
        time_t nTime=0;
        time(
&nTime ) ;
        tm
*tm1 = localtime( &nTime ) ;
        sprintf(msg,
"%04d%02d%02d%02d%02d%02d",tm1->tm_year+1900,tm1->tm_mon+1,tm1->tm_mday,tm1->tm_hour,tm1->tm_min,tm1->tm_sec);

        stream.send_n(msg,
sizeof(msg));
        stream.close();
    }

    server.close();

   
return
0;
}



编译能够通过,但为何我运行这段代码的时候老是报错:bind failed:WSA startup not initialized
发表于 2008-4-4 15:45:35 | 显示全部楼层
用ACE_TMAIN替换main,或者自己调用WSAStartup
 楼主| 发表于 2008-4-5 23:40:34 | 显示全部楼层
谢谢,这个问题解决了,不过又出现新的问题了。就是我用ACE写的程序在debug模式下推出的时候总是有内存泄露,不知是怎么回事啊
int ACE_TMAIN (int, ACE_TCHAR *[])//int _tmain(int argc, _TCHAR* argv[])
{      
          ACE_INET_Addr addr(1500);   
          ACE_SOCK_Acceptor server;   
          ACE_SOCK_Stream stream;   
          if(server.open(addr)==-1)   
          {
                   ACE_DEBUG ((LM_DEBUG,            ACE_TEXT ("(%P|%t) %p\n"),            ACE_TEXT ("bind failed")));        
                   return 1;   
          }   

          char msg[15];   
          while(server.accept(stream)!=-1)     {
                  ACE_INET_Addr raddr;
                  stream.get_remote_addr(raddr);
                  ACE_DEBUG ((LM_DEBUG,ACE_TEXT ("(%P|%t) connect:%s %d\n"),raddr.get_host_addr(),raddr.get_port_number()));      

                  //get current time
                  time_t nTime=0;
                  time( &nTime ) ;
                  tm *tm1 = localtime( &nTime ) ;
                  sprintf(msg,"%04d%02d%02d%02d%02d%02d",tm1->tm_year+1900,tm1->tm_mon+1,tm1->tm_mday,tm1->tm_hour,tm1->tm_min,tm1->tm_sec);
                  stream.send_n(msg,sizeof(msg));
                  stream.close();
           }   
           server.close();      
         
           return 0;
}

The thread 'Win32 Thread' (0x1058) has exited with code -1073741510 (0xc000013a).
Detected memory leaks!
Dumping objects ->
{168} normal block at 0x003BC048, 8 bytes long.
Data: <  ;     > 10 B7 3B 00 CD CD CD CD
{167} normal block at 0x003BBFF8, 20 bytes long.
Data: <  Z       B     > 1C F9 5A 00 0A 01 00 00 F8 17 42 00 03 00 00 00
{166} normal block at 0x003BBF98, 32 bytes long.
Data: << Z  o          > 3C FB 5A 00 F8 6F 15 00 FF FF FF FF 00 00 00 00
{165} normal block at 0x003BBF38, 32 bytes long.
Data: << Z  o          > 3C FB 5A 00 C0 6F 15 00 FF FF FF FF 00 00 00 00
{164} normal block at 0x003BBED8, 32 bytes long.
Data: <  Z  o          > 1C FB 5A 00 88 6F 15 00 FF FF FF FF 00 00 00 00
{163} normal block at 0x003BBE90, 8 bytes long.
Data: <  Z     > 0C FB 5A 00 00 00 00 00
{162} normal block at 0x003BBE30, 32 bytes long.
Data: <  Z Po          > 1C FB 5A 00 50 6F 15 00 FF FF FF FF 00 00 00 00
{161} normal block at 0x003BBDD0, 32 bytes long.
Data: << Z  o          > 3C FB 5A 00 18 6F 15 00 FF FF FF FF 00 00 00 00
{160} normal block at 0x003BBD70, 32 bytes long.
Data: << Z  n          > 3C FB 5A 00 E0 6E 15 00 FF FF FF FF 00 00 00 00
{159} normal block at 0x003BBD10, 32 bytes long.
Data: <  Z  n          > 1C FB 5A 00 A8 6E 15 00 FF FF FF FF 00 00 00 00
{158} normal block at 0x003BBC28, 172 bytes long.
Data: <, Z      m      > 2C FB 5A 00 01 00 00 00 C8 6D 15 00 FF FF FF FF
{157} normal block at 0x003BBBB8, 52 bytes long.
Data: <  Z             > 94 FA 5A 00 01 00 00 00 00 00 00 00 00 00 00 00
{156} normal block at 0x003BBB78, 4 bytes long.
Data: <    > FF FF FF FF
{155} normal block at 0x003BBB20, 24 bytes long.
Data: < i              > 88 69 15 00 FF FF FF FF 00 00 00 00 00 00 00 00
{154} normal block at 0x003BBAC8, 24 bytes long.
Data: <;Pi              > 50 69 15 00 FF FF FF FF 00 00 00 00 00 00 00 00
{153} normal block at 0x003BBA70, 24 bytes long.
Data: < i              > 18 69 15 00 FF FF FF FF 00 00 00 00 00 00 00 00
{152} normal block at 0x003BBA20, 16 bytes long.
Data: <                > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
{151} normal block at 0x003BB9C0, 36 bytes long.
Data: <p Z           ; > 70 FC 5A 00 02 00 00 00 01 CD CD CD B0 B8 3B 00
{150} normal block at 0x003BB968, 28 bytes long.
Data: < -              > C8 2D 15 00 FF FF FF FF 00 00 00 00 00 00 00 00
{149} normal block at 0x003BB918, 16 bytes long.
Data: <                > 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
{148} normal block at 0x003BB8B0, 40 bytes long.
Data: <  Z             > F8 FA 5A 00 02 00 00 00 01 CD CD CD 00 00 00 00
{145} normal block at 0x003BB758, 8 bytes long.
Data: <H ;   ; > 48 C0 3B 00 F8 BF 3B 00
{144} normal block at 0x003BB710, 8 bytes long.
Data: <X ;  Bd > 58 B7 3B 00 E4 42 64 00
{143} normal block at 0x003BB6C8, 12 bytes long.
Data: <H ;     @gd > 48 C0 3B 00 02 00 00 00 40 67 64 00
{142} normal block at 0x003BB600, 136 bytes long.
Data: < X              > 00 58 00 00 00 00 00 00 00 00 00 00 00 00 00 00
{141} normal block at 0x01040068, 13060 bytes long.
Data: <                > 00 00 00 00 00 00 00 00 FF FF FF FF 00 00 00 00
{140} normal block at 0x003BB598, 44 bytes long.
Data: <    8V          > 00 00 00 00 38 56 15 00 FF FF FF FF 00 00 00 00
{139} normal block at 0x003BB540, 28 bytes long.
Data: < V              > 00 56 15 00 FF FF FF FF 00 00 00 00 00 00 00 00
{134} normal block at 0x003BA500, 4096 bytes long.
Data: <                > CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD CD
{133} normal block at 0x003BA498, 40 bytes long.
Data: <  ;          U  > 00 A5 3B 00 00 00 00 00 00 04 00 00 90 55 15 00
{132} normal block at 0x003BA438, 32 bytes long.
Data: <  Z XU          > 1C FB 5A 00 58 55 15 00 FF FF FF FF 00 00 00 00
{131} normal block at 0x003BA3A0, 88 bytes long.
Data: < ?[  ?[         > C4 3F 5B 00 A0 3F 5B 00 00 CD CD CD 00 04 00 00
Object dump complete.
The program '[6120] ACE_Text.exe: Native' has exited with code -1073741510 (0xc000013a).

[ 本帖最后由 z1y1m1 于 2008-4-5 23:49 编辑 ]
发表于 2012-6-7 15:33:53 | 显示全部楼层
加上ACE::init()
您需要登录后才可以回帖 登录 | 用户注册

本版积分规则

Archiver|手机版|小黑屋|ACE Developer ( 京ICP备06055248号 )

GMT+8, 2024-11-23 16:13 , Processed in 0.016254 second(s), 6 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表