• Welcome to Valhalla Legends Archive.
 

good link for winsock newbies (C++)

Started by MoNksBaNe_Agahnim, November 17, 2003, 12:02 PM

Previous topic - Next topic

iago

He just indents more and more; he really needs to clean up his code a bit.

Also, I don't think this is right: cout << "\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n";

I'm pretty sure there's an easier way to clear the screen! :)

Besides that, it's a good starting point, I actually borrowed some of his code a long time ago
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


CupHead

It's actually PSC that formats it like that.

iago

ah, I thought he just had a lot of nested stuff...


Also, he has goto's, which make it hardish to read :/
This'll make an interesting test for broken AV:
QuoteX5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*


MoNksBaNe_Agahnim

ya he gooned it on the system clear... doing system("cls"); is a lot better...all he did was make it move down a bunch of lines.

TheMinistered

#5
If you are looking for some sample code that uses winsock, here is some that I wrote:


#include "winsock2.h"
#include "stdio.h"

#define LISTEN_PORT 54



   // INITIALIZE WINSOCK
   WSADATA wsadata;

   if (WSAStartup (MAKEWORD(2,2), &wsadata) != 0) {
      printf("The call to the following function failed: WSAStartup\n");
      return FALSE;
   }

   // CREATE THE SOCKET
   SOCKET listensocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);

   if (listensocket == INVALID_SOCKET) {
      printf("The call to the following function failed: socket\n");
      return FALSE;
   }

   // FILL IN THE ADDRESS STRUCTURE (THE "NAME")
   SOCKADDR_IN sockaddr;

   sockaddr.sin_family = AF_INET;
   sockaddr.sin_addr.s_addr = INADDR_ANY;
   sockaddr.sin_port = htons(LISTEN_PORT);

   // BIND THE NAME TO THE SOCKET
   int nReturn = bind(listensocket, (SOCKADDR*)&sockaddr, sizeof(SOCKADDR));

   if (nReturn == SOCKET_ERROR) {
      printf("The call to the following function failed: bind\n");
      closesocket(listensocket);
      return FALSE;
   }

   // START LISTENING ON THE SOCKET
   nReturn = listen(listensocket, SOMAXCONN);

   if (nReturn == SOCKET_ERROR) {
      printf("The call to the following function failed: listen\n");
      closesocket(listensocket);
      return FALSE;
   }
   
   // CLEAN UP AFTER WINSOCK
   closesocket(listensocket);
   WSACleanup();


references: www.msdn.microsoft.com

thetempest

very nice sample code  ;D

if you want a tutorial that gives sample code along with it of that quality you might wanna check this out.

www.hal-pc.org/~johnnie2/winsock.html

dev invisible