/***************************************************************************/
/*
*/
/* FileName: main.cpp
*/
/*
*/
/* Details: XBOX Socket Basics (prt10)
*/
/*
*/
/* Author: Ben_3D
*/
/*
*/
/* www.xfactordev.net
*/
/*
*/
/***************************************************************************/
//Main header file for the XDK
#include
<xtl.h>
#include
<stdio.h>
// Use this simple function to save our data..feed information back into a
// text file in the same directory as our xbe.
void
debug(char *str)
{
// Used during debugging of the program
FILE *fp;
fp=fopen("D:\\DebugInfo.txt",
"a+");
fprintf(fp, "%s\n", str);
fclose(fp);
}
void
Initialise()
{
/*
-1- Initilize Any Main Functions
*/
debug("Starting up network");
XNetStartupParams xnsp;
memset(&xnsp, 0, sizeof(xnsp));
xnsp.cfgSizeOfStruct = sizeof(XNetStartupParams);
xnsp.cfgFlags = XNET_STARTUP_BYPASS_SECURITY;
INT
err = XNetStartup(&xnsp);
DWORD TIMELIMIT = 6000;
DWORD dwStart = GetTickCount();
debug("Network started, wait for 6 seconds");
while ((GetTickCount() - dwStart) <
TIMELIMIT)
{
// wait it out!!
}
}
void
Connect()
{
WSADATA WsaData;
int iResult = WSAStartup( MAKEWORD(2,2), &WsaData
);
if( iResult != NO_ERROR )
debug("Error at WSAStartup");
char aa[5000];
SOCKET m_socket;
m_socket = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
int whathappened=WSAGetLastError ();
wsprintf(aa, "SOCKET = %ld\n", m_socket);
debug(aa);
wsprintf(aa, "Whathappened= %ld\n", whathappened);
debug(aa);
if (m_socket == INVALID_SOCKET) {
debug("Error at socket()");
WSACleanup();
return;
}
sockaddr_in service;
service.sin_family = AF_INET;
service.sin_addr.s_addr = inet_addr("66.218.71.198");
// yahoo.com -> "66.218.71.198"
//service.sin_addr.s_addr = inet_addr("192.168.0.20");
service.sin_port = htons(80);
int results=connect(m_socket,(sockaddr*) &service,sizeof(struct
sockaddr));
if( results == SOCKET_ERROR)
{
debug("Error at connect()");
}
send(m_socket, "GET / \r\n", strlen("GET / \r\n"), 0);
int rr = 1;
while (rr)
{
rr = recv(m_socket, aa, 500, 0);
debug("recv:");
debug(aa);
}
}
void
CleanUp()
{
debug("exiting");
//
// Shutdown Winsock
//
WSACleanup();
XNetCleanup();
}
void
ReBoot()
{
LD_LAUNCH_DASHBOARD LaunchData = { XLD_LAUNCH_DASHBOARD_MAIN_MENU };
XLaunchNewImage( NULL, (LAUNCH_DATA*)&LaunchData );
}
//Application entry point
void
__cdecl main()
{
// Initilisze our xbox so we can connect to the network card
Initialise();
// Connect to our socket, get the html from yahoo and save it to a debug
text file
Connect();
// Tidy up and be a good boy
CleanUp();
// Reboot our xbox as all it done and finished.
ReBoot();
}
|