By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,234 Members | 1,872 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,234 IT Pros & Developers. It's quick & easy.

errors

P: n/a
hi

i have msdn tcp/ip sample :

#include "stdafx.h"
//int _tmain(int argc, _TCHAR* argv[])
//{
// return 0;
//}

#include "winsock2.h"

void main() {

// Initialize Winsock.
WSADATA wsaData;
int iResult = WSAStartup( MAKEWORD(2,2), &wsaData );
if ( iResult != NO_ERROR )
printf("Error at WSAStartup()\n");

// Create a socket.
SOCKET m_socket;
m_socket = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );

if ( m_socket == INVALID_SOCKET ) {
printf( "Error at socket(): %ld\n", WSAGetLastError() );
WSACleanup();
return;
}

// Connect to a server.
sockaddr_in clientService;

clientService.sin_family = AF_INET;
clientService.sin_addr.s_addr = inet_addr( "127.0.0.1" );
clientService.sin_port = htons( 27015 );

if ( connect( m_socket, (SOCKADDR*) &clientService,
sizeof(clientService) ) == SOCKET_ERROR) {
printf( "Failed to connect.\n" );
WSACleanup();
return;
}

// Send and receive data.
int bytesSent;
int bytesRecv = SOCKET_ERROR;
char sendbuf[32] = "Client: Sending data.";
char recvbuf[32] = "";

bytesSent = send( m_socket, sendbuf, strlen(sendbuf), 0 );
printf( "Bytes Sent: %ld\n", bytesSent );

if ( bytesRecv == 0 ||
(bytesRecv == SOCKET_ERROR &&
WSAGetLastError()== WSAECONNRESET ))
{
bytesRecv = recv( m_socket, recvbuf, 32, 0 );
if ( bytesRecv == -1 )
{
printf( "Connection Closed.\n");
break;
}
if (bytesRecv < 0)
return;
printf( "Bytes Recv: %ld\n", bytesRecv );
}

WSACleanup();
return;
}

iam trying to compile this code on Visual studio 2005 express edition
with PlatformSDK (winxp)
i have this errors:

------ Build started: Project: 2223, Configuration: Debug Win32 ------
Compiling...
2223.cpp
c:\program files\microsoft visual studio
8\vc\platformsdk\include\specstrings.h(334) : warning C4005:
'__reserved' : macro redefinition
c:\program files\microsoft visual studio
8\vc\include\sal.h(702) : see previous definition of '__reserved'
c:\program files\microsoft visual studio
8\vc\platformsdk\include\specstrings.h(341) : warning C4005:
'__checkReturn' : macro redefinition
c:\program files\microsoft visual studio
8\vc\include\sal.h(703) : see previous definition of '__checkReturn'
c:\program files\microsoft visual studio
8\vc\platformsdk\include\specstrings.h(344) : warning C4005:
'__typefix' : macro redefinition
c:\program files\microsoft visual studio
8\vc\include\sal.h(704) : see previous definition of '__typefix'
c:\program files\microsoft visual studio
8\vc\platformsdk\include\specstrings.h(349) : warning C4005:
'__override' : macro redefinition
c:\program files\microsoft visual studio
8\vc\include\sal.h(705) : see previous definition of '__override'
c:\program files\microsoft visual studio
8\vc\platformsdk\include\specstrings.h(350) : warning C4005:
'__fallthrough' : macro redefinition
c:\program files\microsoft visual studio
8\vc\include\sal.h(714) : see previous definition of '__fallthrough'
c:\program files\microsoft visual studio
8\vc\platformsdk\include\specstrings.h(351) : warning C4005:
'__callback' : macro redefinition
c:\program files\microsoft visual studio
8\vc\include\sal.h(706) : see previous definition of '__callback'
c:\program files\microsoft visual studio
8\vc\platformsdk\include\specstrings.h(352) : warning C4005: '__in' :
macro redefinition
c:\program files\microsoft visual studio
8\vc\include\sal.h(499) : see previous definition of '__in'
c:\program files\microsoft visual studio
8\vc\platformsdk\include\specstrings.h(353) : warning C4005: '__out' :
macro redefinition
c:\program files\microsoft visual studio
8\vc\include\sal.h(508) : see previous definition of '__out'
c:\program files\microsoft visual studio
8\vc\platformsdk\include\specstrings.h(354) : warning C4005: '__inout'
: macro redefinition
c:\program files\microsoft visual studio
8\vc\include\sal.h(527) : see previous definition of '__inout'
c:\program files\microsoft visual studio
8\vc\platformsdk\include\specstrings.h(356) : warning C4005:
'__out_ecount' : macro redefinition
c:\program files\microsoft visual studio
8\vc\include\sal.h(509) : see previous definition of '__out_ecount'
c:\program files\microsoft visual studio
8\vc\platformsdk\include\specstrings.h(357) : warning C4005:
'__in_ecount' : macro redefinition
c:\program files\microsoft visual studio
8\vc\include\sal.h(500) : see previous definition of '__in_ecount'
c:\program files\microsoft visual studio
8\vc\platformsdk\include\specstrings.h(358) : warning C4005:
'__inout_ecount' : macro redefinition
c:\program files\microsoft visual studio
8\vc\include\sal.h(528) : see previous definition of '__inout_ecount'
c:\program files\microsoft visual studio
8\vc\platformsdk\include\specstrings.h(359) : warning C4005:
'__out_bcount' : macro redefinition
c:\program files\microsoft visual studio
8\vc\include\sal.h(510) : see previous definition of '__out_bcount'
c:\program files\microsoft visual studio
8\vc\platformsdk\include\specstrings.h(360) : warning C4005:
'__in_bcount' : macro redefinition
c:\program files\microsoft visual studio
8\vc\include\sal.h(501) : see previous definition of '__in_bcount'
c:\program files\microsoft visual studio
8\vc\platformsdk\include\specstrings.h(361) : warning C4005:
'__inout_bcount' : macro redefinition
c:\program files\microsoft visual studio
8\vc\include\sal.h(529) : see previous definition of '__inout_bcount'
c:\documents and settings\администратор\мои
документы\visual studio 2005\projects\2223\2223\2223.cpp(51) :
warning C4267: 'argument' : conversion from 'size_t' to 'int', possible
loss of data
c:\documents and settings\администратор\мои
документы\visual studio 2005\projects\2223\2223\2223.cpp(62) :
error C2043: illegal break
Build log was saved at "file://c:\Documents and
Settings\Администратор\Мои документы\Visual
Studio 2005\Projects\2223\2223\Debug\BuildLog.htm"
2223 - 1 error(s), 16 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped
==========

Whats wrong ?

Jun 28 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
errmaker wrote:
hi

i have msdn tcp/ip sample :

#include "stdafx.h"
//int _tmain(int argc, _TCHAR* argv[])
//{
// return 0;
//}

#include "winsock2.h"

void main() {

// Initialize Winsock.
WSADATA wsaData;
int iResult = WSAStartup( MAKEWORD(2,2), &wsaData );
if ( iResult != NO_ERROR )
printf("Error at WSAStartup()\n");

// Create a socket.
SOCKET m_socket;
m_socket = socket( AF_INET, SOCK_STREAM, IPPROTO_TCP );

if ( m_socket == INVALID_SOCKET ) {
printf( "Error at socket(): %ld\n", WSAGetLastError() );
WSACleanup();
return;
}

// Connect to a server.
sockaddr_in clientService;

clientService.sin_family = AF_INET;
clientService.sin_addr.s_addr = inet_addr( "127.0.0.1" );
clientService.sin_port = htons( 27015 );

if ( connect( m_socket, (SOCKADDR*) &clientService,
sizeof(clientService) ) == SOCKET_ERROR) {
printf( "Failed to connect.\n" );
WSACleanup();
return;
}

// Send and receive data.
int bytesSent;
int bytesRecv = SOCKET_ERROR;
char sendbuf[32] = "Client: Sending data.";
char recvbuf[32] = "";

bytesSent = send( m_socket, sendbuf, strlen(sendbuf), 0 );
printf( "Bytes Sent: %ld\n", bytesSent );

if ( bytesRecv == 0 ||
(bytesRecv == SOCKET_ERROR &&
WSAGetLastError()== WSAECONNRESET ))
{
bytesRecv = recv( m_socket, recvbuf, 32, 0 );
if ( bytesRecv == -1 )
{
printf( "Connection Closed.\n");
break;
}
if (bytesRecv < 0)
return;
printf( "Bytes Recv: %ld\n", bytesRecv );
}

WSACleanup();
return;
}

iam trying to compile this code on Visual studio 2005 express edition
with PlatformSDK (winxp)
i have this errors:

------ Build started: Project: 2223, Configuration: Debug Win32 ------
Compiling...
2223.cpp
c:\program files\microsoft visual studio
8\vc\platformsdk\include\specstrings.h(334) : warning C4005:
'__reserved' : macro redefinition
c:\program files\microsoft visual studio
8\vc\include\sal.h(702) : see previous definition of '__reserved'
c:\program files\microsoft visual studio
8\vc\platformsdk\include\specstrings.h(341) : warning C4005:
'__checkReturn' : macro redefinition
c:\program files\microsoft visual studio
8\vc\include\sal.h(703) : see previous definition of '__checkReturn'
c:\program files\microsoft visual studio
8\vc\platformsdk\include\specstrings.h(344) : warning C4005:
'__typefix' : macro redefinition
c:\program files\microsoft visual studio
8\vc\include\sal.h(704) : see previous definition of '__typefix'
c:\program files\microsoft visual studio
8\vc\platformsdk\include\specstrings.h(349) : warning C4005:
'__override' : macro redefinition
c:\program files\microsoft visual studio
8\vc\include\sal.h(705) : see previous definition of '__override'
c:\program files\microsoft visual studio
8\vc\platformsdk\include\specstrings.h(350) : warning C4005:
'__fallthrough' : macro redefinition
c:\program files\microsoft visual studio
8\vc\include\sal.h(714) : see previous definition of '__fallthrough'
c:\program files\microsoft visual studio
8\vc\platformsdk\include\specstrings.h(351) : warning C4005:
'__callback' : macro redefinition
c:\program files\microsoft visual studio
8\vc\include\sal.h(706) : see previous definition of '__callback'
c:\program files\microsoft visual studio
8\vc\platformsdk\include\specstrings.h(352) : warning C4005: '__in' :
macro redefinition
c:\program files\microsoft visual studio
8\vc\include\sal.h(499) : see previous definition of '__in'
c:\program files\microsoft visual studio
8\vc\platformsdk\include\specstrings.h(353) : warning C4005: '__out' :
macro redefinition
c:\program files\microsoft visual studio
8\vc\include\sal.h(508) : see previous definition of '__out'
c:\program files\microsoft visual studio
8\vc\platformsdk\include\specstrings.h(354) : warning C4005: '__inout'
: macro redefinition
c:\program files\microsoft visual studio
8\vc\include\sal.h(527) : see previous definition of '__inout'
c:\program files\microsoft visual studio
8\vc\platformsdk\include\specstrings.h(356) : warning C4005:
'__out_ecount' : macro redefinition
c:\program files\microsoft visual studio
8\vc\include\sal.h(509) : see previous definition of '__out_ecount'
c:\program files\microsoft visual studio
8\vc\platformsdk\include\specstrings.h(357) : warning C4005:
'__in_ecount' : macro redefinition
c:\program files\microsoft visual studio
8\vc\include\sal.h(500) : see previous definition of '__in_ecount'
c:\program files\microsoft visual studio
8\vc\platformsdk\include\specstrings.h(358) : warning C4005:
'__inout_ecount' : macro redefinition
c:\program files\microsoft visual studio
8\vc\include\sal.h(528) : see previous definition of '__inout_ecount'
c:\program files\microsoft visual studio
8\vc\platformsdk\include\specstrings.h(359) : warning C4005:
'__out_bcount' : macro redefinition
c:\program files\microsoft visual studio
8\vc\include\sal.h(510) : see previous definition of '__out_bcount'
c:\program files\microsoft visual studio
8\vc\platformsdk\include\specstrings.h(360) : warning C4005:
'__in_bcount' : macro redefinition
c:\program files\microsoft visual studio
8\vc\include\sal.h(501) : see previous definition of '__in_bcount'
c:\program files\microsoft visual studio
8\vc\platformsdk\include\specstrings.h(361) : warning C4005:
'__inout_bcount' : macro redefinition
c:\program files\microsoft visual studio
8\vc\include\sal.h(529) : see previous definition of '__inout_bcount'
c:\documents and settings\администратор\мои
документы\visual studio 2005\projects\2223\2223\2223.cpp(51) :
warning C4267: 'argument' : conversion from 'size_t' to 'int', possible
loss of data
c:\documents and settings\администратор\мои
документы\visual studio 2005\projects\2223\2223\2223.cpp(62) :
error C2043: illegal break
Build log was saved at "file://c:\Documents and
Settings\Администратор\Мои документы\Visual
Studio 2005\Projects\2223\2223\Debug\BuildLog.htm"
2223 - 1 error(s), 16 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped
==========

Whats wrong ?


This likely is not a standard C++ issue (as hinted at by the double
underscores in the conflicting identifiers), so you'll want to take it
to a Microsoft group. See this FAQ for some possibilities:

http://www.parashift.com/c++-faq-lit...t.html#faq-5.9

Cheers! --M

Jun 28 '06 #2

P: n/a
errmaker wrote:
hi

i have msdn tcp/ip sample :

#include "stdafx.h"
//int _tmain(int argc, _TCHAR* argv[])
//{
// return 0;
//}

#include "winsock2.h"

void main() {

[redacted]


void main() is illegal. The program is ill formed, and therefore any
other problems are irrelevant.
Jun 28 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.