Data Packets

Started by
21 comments, last by hplus0603 14 years, 11 months ago
Ok, so I added the comma's like you said..but I am still getting some issues...same errors.

#include <winsock2.h>#include "config.hpp"#include "util.hpp"#include <stdio.h>int serverstart(){WSADATA wsaData;int ErgoServ = WSAStartup(MAKEWORD(2,2), &wsaData);if(ErgoServ != 0){    printf("WSAStartup Failed: %s\n", WSAGetLastError);    WSACleanup();    return 1;}SOCKET s = socket(AF_INET, SOCK_STREAM, 0);if(s == INVALID_SOCKET){    printf("Socket creation failed: %s\n", WSAGetLastError);    WSACleanup();    return 1;}sockaddr_in sin;sin.sin_port = htons(80);sin.sin_addr.s_addr = INADDR_ANY;sin.sin_family = AF_INET;if(bind(s,(sockaddr*),&sin sizeof,(sin)) == SOCKET_ERROR){    printf("Bind failed: %s\n", WSAGetLastError);    WSACleanup();    return 1;}while(listen(s, SOMAXCONN) == SOCKET_ERROR);SOCKET client;int lin = sizeof(sin);client = accept(s,(sockaddr*)&sin, &lin);printf("Connection Establised");char buf[80] = PACKET_WELCOME;send(client,buf,sizeof(buf),0);closesocket(s);closesocket(client);WSACleanup();return 0;}


Also so you know I am not as new to C++ as it may seem; I've been working with it for awhile(a year maybe less) I learn better by doing the harder things then the easier things..I know it's weird an you probably don't believe me but thats ok, everyone learns differently..

Thanks again for everyone's help
Advertisement
I've already pointed out that your printf messages are incorrect and how you should fix them. Maybe you should drop printf (which you may have kept because a tutorial included it) and use the C++ streams instead, which you may be more familiar with:
if(/* something went wrong */){    std::cerr << "Something Failed: " << WSAGetLastError() << '\n';    WSACleanup();    return 1;}

Also you have gotten the commas almost completely wrong. I separated the arguments for you into quoted strings, but you have ignored that and inserted commas seemingly at random.

I appreciate that you like to learn by trying hard things. But if your current difficulty is with the C++ language then why not challenge yourself by concentrating on learning that?
You don't even know C++ programming. There is no way that you should be working on networking code in C++ right now; you need to first learn the language before you'll have any chance of writing useful networking code.
enum Bool { True, False, FileNotFound };

This topic is closed to new replies.

Advertisement