All pastes #541858 Raw Edit

VoiDeD

public cpp v1 · immutable
·published 2007-06-05 17:02 UTC
rendered paste body
#include "..\VoiDAPI\VoiDAPI.h"#include <stdio.h>#pragma warning(disable : 4482) // nonstandard extension used: enum 'enum' used in qualified name// GUI classesVWindow *window;VTextBox *status;// Networking classesVThread *thread;VSocket *server = NULL;VSocket *client = NULL;// this function will be called when the thread is startedvoid start(VThread *sender, void *param){	status->AppendText("[NET] Initializing server...\r\n");	// create a new socket	server = new VSocket(		VSocketAddressFamily::FAMILY_INET,		VSocketType::TYPE_STREAM,		VSocketProtocol::PROTO_TCP	);	status->AppendText("[NET] Binding...\r\n");	// bind it to localhost:1000	server->Bind("127.0.0.1", 1000);		status->AppendText("[NET] Listening...\r\n");	// put the socket into listening mode	server->Listen();	// loop until we get a client	while (client == NULL)	{		client = server->Accept();		thread->Sleep(10);	}	status->AppendText("[NET] Client connected!\r\n");	// main loop	while (true)	{		// recieve any data		char *data = client->Recieve(256);		// display the data if it is useful		if (data[0] != NULL)		{			STRING_ALLOCATE(szBuff, 300);			sprintf_s(szBuff, 300,"[CLIENT] %s\r\n", data);			status->AppendText(szBuff);			status->ScrollToCaret();		}		thread->Sleep(10);	}}// this function is called after the window is createdvoid init(VWindow *sender){	// start the thread	thread->Start();}// this function is called when the user closes the windowvoid quit(VWindow *sender){	thread->Kill();	sender->Destroy();}int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd){	// create a new window and register the created and close events	window = new VWindow("VoiDAPI Sockets", new VSize(300, 500));	window->RegisterEvent(WM_CLOSE, &quit);	// WM_CREATED is a custom VoiDAPI message called when the window is shown	// but before the main message loop	window->RegisterEvent(WM_CREATED, &init);	// create a status multi-line textbox to display information	status = new VTextBox(new VSize(294, 468), new VPoint(0, 0), true);	status->SendMessage(EM_SETREADONLY, TRUE, 0);	// create a thread which will handle networking	thread = new VThread(start, NULL);	// add the status box to the window	window->AddControl(status);	// finally, show the window	window->Show();}