Simple socket help!!
Sep 3, 2012 at 4:04pm UTC
hey i am absolute begnier in network programming i am not very good at some parts of C++ and c any ways i made this socket i do not what the error is and the code is this :
header file:
1 2 3 4 5 6 7
#pragma comment(lib , "wS2_32.lib");
#include<sdkddkver.h>
#include<conio.h>
#include<stdio.h>
#include<WinSock2.h>
#include<Windows.h>
#include<iostream>
server:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
#include "cyberspace.h"
using namespace std;
void main()
long answer;
WSAData wsaData;
WORD DLLVERSION;
DLL=MAKEWORD(2,1);
answer=WSAStartup(DLLVERSION,&wsaData);
SOCKADOR_IN addr;
int addrlen= sizeof (addr);
SOCKET sListen;
SOCKET sConnect;
sConnect=socket(AF_INET,SOCK_STREAM,NULL);
addr.sin_addr.s_addr=inet_addr("127.0.0.1" );
addr.sin_family=AF_INET;
addr.sin_port = htons(1234);
sListen=socket(AF_INET,SOCK_STREAM,NULL);
bind(sListen,(SOCKADDR*)&addr,sizeof (addr))
listen(sListen,SOMAXCONN);
if (;;)
{
cout<<"Awaiting for incoming connection please wait" ;
if (sConnect= accept(sListen, (SOCKADDR*)&addr,&addrlen))
{
cout<<"Connection was found..." <<endl;
}
}
}
After please present the full code without the compilation error
Sep 3, 2012 at 6:37pm UTC
Do you have written any program in C or C++ before? To me it seems that you do not.
Sep 3, 2012 at 6:47pm UTC
sorry and thanks i made it work by the way i did do it
Topic archived. No new replies allowed.