正如问题所说,我遇到以下代码的问题:
#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);
};
我正在使用Code :: Blocks。我在构建时遇到以下错误:
/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 ===|
我在引用的includes.h中包含以下内容:
#include <sys/socket.h>
#include <sys/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <iostream>
我错过了指令或图书馆吗? SOCKET拼写是不同的?任何照明都会很棒!
答案 0 :(得分:1)
套接字文件描述符只是一个整数。因此,请在代码中将SOCKET
替换为int
,或使用typedef
。 (我不确定你之前在哪里看过SOCKET
,但这不是标准的。)