error LNK2019: unresolved external symbol __imp__socket@12


해결방법 : #pragma comment(lib,"wsock32.lib") 추가




'프로그래밍 > Network' 카테고리의 다른 글

[winsock2] Nagle 알고리즘  (0) 2013.03.08
PF_INET , AF_INET  (0) 2013.03.06
[WINAPI] Local IP 얻어오기  (0) 2013.03.05
by 개발자가 되자! 2013. 3. 11. 11:53

환경 : Visual Studio 6.0 (간단한 코딩환경을 위해)

와 미치는줄알았다..

Nagle optVal이 -858993664값이 나온다..

↓해답으로 이동↓


일단 Nagle 알고리즘을 간단히 설명하면

(위키 : http://en.wikipedia.org/wiki/Nagle's_algorithm)


send ( "a" );

send ( "b" );

send ( "c" );

send ( "d" );

send ( "e" );


이렇게 전송을하면

1. buffer [ a ,   ]   //a가 버퍼에 쌓임

2. 데이터send중이 아님 => buffer를 send함

3. 보내는동안 buffer에 나머지 데이터가 쌓임

    buffer [ b, c, d, e,  ]

4. buffer가 보내짐



결과를 보면

send ("a");

send ("bcde");

이런식으로 보내지게된다.


왜 문제가 생겼냐면,

받는쪽에서 NULL 문자를 기준으로 출력했을때


a

b
c

d

e


이런 결과값이 출력되어야 하지만



a

bcde


이렇게 출력된다


쒯..

알겠는가? 문제점을?

(Nagle + TCP특성(stream))


어찌어찌하여 Nagle을 찾게되었고

MSDN에서 보니

  int optVal;
  int optLen = sizeof(int);

  if (getsockopt(ListenSocket, 
    SOL_SOCKET, 
    SO_ACCEPTCONN, 
    (char*)&optVal, 
    &optLen) != SOCKET_ERROR) 

    printf("SockOpt Value: %ld\n", optVal); 

예제 코딩이 이런식으로 되어있었다.


뭐가 문제인지.. optVal 값은  Option 값이므로 TRUE, FALSE 가 나와야한다

하지만 미친 -858993664 이런 값이나오니...


인터넷 검색해도 이 코드고, 열혈강의도 이런 코드였다.

뭐가문제냐.... 해서 30분동안 헤메다가



찾아낸 Nagle알고리즘 설정방법은 바로 요것

1. char형으로  처음부터 선언하는것

1
2
3
4
char optVal;
int optLen = sizeof(optVal);

if(getsockopt(mySocketAddr, IPPROTO_TCP, TCP_NODELAY, &optVal, &optLen) == 0)
{

//성공적인 수행

}

2.(char)optVal 로 형변환을 하여 출력

1
2
3
4

int optVal; int optLen = sizeof(optVal); if(getsockopt(mySocketAddr, IPPROTO_TCP, TCP_NODELAY, &optVal, &optLen) == 0)

{

(char)optVal;

}


optVal... 네이년..

char라고 왜 말을못해!!

이렇게 쉬운 실수를 하다니..ㅠㅠ


int인척 둔갑하지마라

'프로그래밍 > Network' 카테고리의 다른 글

error LNK2019: unresolved external symbol __imp__socket@12  (0) 2013.03.11
PF_INET , AF_INET  (0) 2013.03.06
[WINAPI] Local IP 얻어오기  (0) 2013.03.05
by 개발자가 되자! 2013. 3. 8. 03:31

PF_INET , AF_INET 차이점

프로토콜 형식을 표현 => PF_INET

주소       형식을 표현 => AF_INET



MSDN에 가보면

 Note that the values for the AF_ address family and PF_ protocol family constants are identical (for example, AF_INET and PF_INET), so either constant can be used.


해석

identical : 아주 동일한!

AF_ address family constants == PF_ protocol family constants ? TRUE!!



SOCKET WSAAPI socket( _In_  int af, _In_  int type, _In_  int protocol );


af 인자를 잠시 살펴보면

AfMeaning
AF_UNSPEC
0

The address family is unspecified.

AF_INET
2

The Internet Protocol version 4 (IPv4) address family.

AF_IPX
6

The IPX/SPX address family. This address family is only supported if the NWLink IPX/SPX NetBIOS Compatible Transport protocol is installed.

This address family is not supported on Windows Vista and later.

AF_APPLETALK
16

The AppleTalk address family. This address family is only supported if the AppleTalk protocol is installed.

This address family is not supported on Windows Vista and later.

AF_NETBIOS
17

The NetBIOS address family. This address family is only supported if the Windows Sockets provider for NetBIOS is installed.

The Windows Sockets provider for NetBIOS is supported on 32-bit versions of Windows. This provider is installed by default on 32-bit versions of Windows.

The Windows Sockets provider for NetBIOS is not supported on 64-bit versions of windows including Windows 7, Windows Server 2008, Windows Vista, Windows Server 2003, or Windows XP.

The Windows Sockets provider for NetBIOS only supports sockets where the type parameter is set to SOCK_DGRAM.

The Windows Sockets provider for NetBIOS is not directly related to the NetBIOSprogramming interface. The NetBIOS programming interface is not supported on Windows Vista, Windows Server 2008, and later.

AF_INET6
23

The Internet Protocol version 6 (IPv6) address family.

AF_IRDA
26

The Infrared Data Association (IrDA) address family.

This address family is only supported if the computer has an infrared port and driver installed.

AF_BTH
32

The Bluetooth address family.

This address family is supported on Windows XP with SP2 or later if the computer has a Bluetooth adapter and driver installed.


by 개발자가 되자! 2013. 3. 6. 17:12

네트워크 프로그래밍을 하다가 포스트합니다.
가끔 IP주소를 알아야 하는데 원도우 네트워크 속성을 보거나, 프롬프트에서 ipconfig 실행합니다.
위와 같은 방법으로 알 수 있습니다. 만. 

Win32API로 Local IP 얻어오는 방법, 여러 IP를 갖고있는 컴퓨터의 IP들을 얻어오는 소스코드, 실행화일 입니다.

Tool : Visual C++ 6.0(Win32API)

소스코드 : GetIPAddr.zip
실행화일 : GetIPexe.zip

실행화면입니다. IP가 3개나 있습니다. (ipconfig 실행한 것과 같네요)


[Source Code]
    :
BOOL GetLocalIPAddr()
{
     WSADATA wsa;
     IN_ADDR addr;

    
     char LocalName[256], IPAddr[15], i = 0;


     if(WSAStartup(MAKEWORD(2,2), &wsa) != 0) return FALSE;

     if(gethostname(LocalName, 256) == SOCKET_ERROR) return FALSE;

    
     HOSTENT *ptr = gethostbyname(LocalName);
     if(ptr == NULL) return FALSE;


     while(ptr->h_addr_list[i] != NULL)
     {
          memcpy(&addr, ptr->h_addr_list[i], ptr->h_length);
          wsprintf(IPAddr, "%s", inet_ntoa(addr));

          SendMessage(hList, LB_ADDSTRING, 0, (LPARAM)IPAddr);  //------------------- Add LocalIP in ListBox.
          i++;
     }
    

     WSACleanup();
     return TRUE;
}

출처 : http://i0nucleus.egloos.com/1919168


'프로그래밍 > Network' 카테고리의 다른 글

error LNK2019: unresolved external symbol __imp__socket@12  (0) 2013.03.11
[winsock2] Nagle 알고리즘  (0) 2013.03.08
PF_INET , AF_INET  (0) 2013.03.06
by 개발자가 되자! 2013. 3. 5. 19:25
| 1 |