c++ sockets

4 replies [Last post]
N0cturn4l
Offline
Neophyte
Joined: 2008/06/21

hey im workin on a c++ sockets and well here is wat it looks like can any 1 tell me wat i did wrong?

// socket.cpp : sockets file

#include "stdafx.h"

using namespace System;

WSADATA ;WsaDat;
if (WSAStartup(MAKEWORD(1, 1), &WsaDat) != 0)
{
printf("WSA Initialization failed.");
}
SOCKET Socket;
Socket = socket(AF_INET, SOCK_STREAM, 0);
if (Socket == INVALID_SOCKET)
{
printf("Socket creation failed.");
}

//We want to use port 50
SockAddr.sin_port = 50;

//We want an internet type connection (TCP/IP)
SockAddr.sin_family = AF_INET;

//We want to listen on IP address 127.0.0.1
//I'll give a few better ways to set thi // s value later
SockAddr.sin_addr.S_un.S_un_b.s_b1 = 127;
SockAddr.sin_addr.S_un.S_un_b.s_b2 = 0;
SockAddr.sin_addr.S_un.S_un_b.s_b3 = 0;
SockAddr.sin_addr.S_un.S_un_b.s_b1 = 1;

if (bind(Socket, (SOCKADDR *)(&SockAddr), sizeof(SockAddr)) == SOCKET_ERROR)
{
printf("Attempt to bind failed.");
}

//We're only going to accept 1 incoming // connection.
listen(Socket, 1);

and as of results

------ Build started: Project: socket, Configuration: Debug Win32 ------
Compiling...
socket.cpp
.\socket.cpp(7) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
.\socket.cpp(7) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
.\socket.cpp(Cool : error C2059: syntax error : 'if'
.\socket.cpp(9) : error C2143: syntax error : missing ';' before '{'
.\socket.cpp(9) : error C2447: '{' : missing function header (old-style formal list?)
.\socket.cpp(12) : error C2146: syntax error : missing ';' before identifier 'Socket'
.\socket.cpp(12) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
.\socket.cpp(12) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
.\socket.cpp(13) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
.\socket.cpp(13) : error C2086: 'int Socket' : redefinition
.\socket.cpp(12) : see declaration of 'Socket'
.\socket.cpp(13) : error C2065: 'AF_INET' : undeclared identifier
.\socket.cpp(13) : error C2065: 'SOCK_STREAM' : undeclared identifier
.\socket.cpp(13) : error C3861: 'socket': identifier not found
.\socket.cpp(14) : error C2059: syntax error : 'if'
.\socket.cpp(15) : error C2143: syntax error : missing ';' before '{'
.\socket.cpp(15) : error C2447: '{' : missing function header (old-style formal list?)
.\socket.cpp(25) : error C2143: syntax error : missing ';' before '.'
.\socket.cpp(25) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
.\socket.cpp(28) : error C2143: syntax error : missing ';' before '.'
.\socket.cpp(28) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
.\socket.cpp(28) : error C2086: 'int SockAddr' : redefinition
.\socket.cpp(25) : see declaration of 'SockAddr'
.\socket.cpp(32) : error C2143: syntax error : missing ';' before '.'
.\socket.cpp(32) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
.\socket.cpp(32) : error C2086: 'int SockAddr' : redefinition
.\socket.cpp(25) : see declaration of 'SockAddr'
.\socket.cpp(33) : error C2143: syntax error : missing ';' before '.'
.\socket.cpp(33) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
.\socket.cpp(33) : error C2086: 'int SockAddr' : redefinition
.\socket.cpp(25) : see declaration of 'SockAddr'
.\socket.cpp(34) : error C2143: syntax error : missing ';' before '.'
.\socket.cpp(34) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
.\socket.cpp(34) : error C2086: 'int SockAddr' : redefinition
.\socket.cpp(25) : see declaration of 'SockAddr'
.\socket.cpp(35) : error C2143: syntax error : missing ';' before '.'
.\socket.cpp(35) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
.\socket.cpp(35) : error C2086: 'int SockAddr' : redefinition
.\socket.cpp(25) : see declaration of 'SockAddr'
.\socket.cpp(38) : error C2059: syntax error : 'if'
.\socket.cpp(39) : error C2143: syntax error : missing ';' before '{'
.\socket.cpp(39) : error C2447: '{' : missing function header (old-style formal list?)
.\socket.cpp(44) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
.\socket.cpp(44) : error C2078: too many initializers
Build log was saved at "file://c:\Documents and Settings\admin\My Documents\Visual Studio 2008\Projects\socket\socket\Debug\BuildLog.htm"
socket - 38 error(s), 0 warning(s)
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

-N0cturn4l-