Nicholas Terry
Nicholas Terry

Reputation: 1930

SOCKET does not name a type

As the question says, I am having an issue with the following code:

#pragma once
#include "includes.h"
#include "buffer.h"


class CSocket
{
    bool udp;
    int format;
    char formatstr[30];
    static sockaddr SenderAddr;
    int receivetext(char*buf, int max);
public:

    SOCKET sockid;
    CSocket(SOCKET sock);
    CSocket();
    ~CSocket();
    bool tcpconnect(char*address, int port, int mode);
    bool tcplisten(int port, int max, int mode);
    CSocket* tcpaccept(int mode);
    char* tcpip();
    void setnagle(bool enabled);
    bool tcpconnected();
    int setsync(int mode);
    bool udpconnect(int port, int mode);
    int sendmessage(char*ip, int port, CBuffer* source);
    int receivemessage(int len, CBuffer*destination);
    int peekmessage(int size, CBuffer*destination);
    int lasterror();
    static char* GetIp(char*address);
    static int SockExit(void);
    static int SockStart(void);
    static char* lastinIP(void);
    static unsigned short lastinPort(void);
    static char* myhost();
    int SetFormat(int mode, char* sep);
};

I am using Code::Blocks. I'm getting the following error at build time:

/home/nick/Desktop/39dylibsource/Base Code/39dll/socket.h|15|error: ‘SOCKET’ does not name a type|
/home/nick/Desktop/39dylibsource/Base Code/39dll/socket.h|16|error: expected ‘)’ before ‘sock’|
/home/nick/Desktop/39dylibsource/Base Code/39dll/main.cpp|16|error: expected constructor, destructor, or type conversion before ‘(’ token|
/home/nick/Desktop/39dylibsource/Base Code/39dll/main.cpp|25|error: expected constructor, destructor, or type conversion before ‘(’ token|
/home/nick/Desktop/39dylibsource/Base Code/39dll/main.cpp|34|error: expected constructor, destructor, or type conversion before ‘(’ token|
/home/nick/Desktop/39dylibsource/Base Code/39dll/main.cpp|43|error: expected constructor, destructor, or type conversion before ‘(’ token|
/home/nick/Desktop/39dylibsource/Base Code/39dll/main.cpp|50|error: expected constructor, destructor, or type conversion before ‘(’ token|
/home/nick/Desktop/39dylibsource/Base Code/39dll/main.cpp|59|error: expected constructor, destructor, or type conversion before ‘(’ token|
/home/nick/Desktop/39dylibsource/Base Code/39dll/main.cpp|66|error: expected constructor, destructor, or type conversion before ‘(’ token|
/home/nick/Desktop/39dylibsource/Base Code/39dll/main.cpp|74|error: expected constructor, destructor, or type conversion before ‘(’ token|
/home/nick/Desktop/39dylibsource/Base Code/39dll/main.cpp|85|error: expected constructor, destructor, or type conversion before ‘(’ token|
||=== Build finished: 11 errors, 0 warnings ===|

I have included the following in the referenced includes.h:

#include <sys/socket.h>
#include <sys/types.h>

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>

Am i missing a directive or library? Is SOCKET spelled different? Any illumination would be great!

Upvotes: 0

Views: 7704

Answers (1)

chrisaycock
chrisaycock

Reputation: 37928

The socket file descriptor is just an integer. So replace SOCKET by int in your code, or use a typedef. (I'm not sure where you saw SOCKET before, but it's not standard.)

Upvotes: 1

Related Questions