Hi guys,
I've tried the socket programming for the first time a very simple one, however I encountered some problems...
here's the code...
====================
Code:
#include <stdio.h>
#include <winsock.h>
#include <iostream.h>
void main()
{
afxsocketinit();
int nRet,sd=0;
int port_to_connect_to = 5555; //port no.
short nPort;
Csocket.socket;
socket.create();
if(!socket.Connect(10.1.3.40,5555))
{
int err = socket.GetLastError();
cout << err << endl;
}
}
=========================================
Gives me the following errors!!
est_wskp2.cpp
C:\C++\IP2\Fe96_vp\Test_wskp2.cpp(11) : error C2065: 'afxsocketinit' : undeclared identifier
C:\C++\IP2\Fe96_vp\Test_wskp2.cpp(16) : error C2065: 'Csocket' : undeclared identifier
C:\C++\IP2\Fe96_vp\Test_wskp2.cpp(16) : error C2228: left of '.socket' must have class/struct/union type
C:\C++\IP2\Fe96_vp\Test_wskp2.cpp(18) : error C2228: left of '.create' must have class/struct/union type
C:\C++\IP2\Fe96_vp\Test_wskp2.cpp(20) : error C2228: left of '.Connect' must have class/struct/union type
C:\C++\IP2\Fe96_vp\Test_wskp2.cpp(20) : error C2143: syntax error : missing ')' before 'constant'
C:\C++\IP2\Fe96_vp\Test_wskp2.cpp(20) : error C2059: syntax error : ')'
C:\C++\IP2\Fe96_vp\Test_wskp2.cpp(21) : error C2143: syntax error : missing ';' before '{'
C:\C++\IP2\Fe96_vp\Test_wskp2.cpp(22) : error C2228: left of '.GetLastError' must have class/struct/union type
Error executing cl.exe.
===========================================
Please can some one help me out with this!!
Basically its to do with making a connection to a server on a port.
If the return code is -1 the connection failed else success
Many Thanks!
John
Code tags added by Kermi3