I keep getting errors in my compiler in brackets of code here {}
All the code works in the compiler except a list of bracket errors for my client and server.
I assume these block declarations give me syntax errors in this structure.
Or that link to source file is incompatible.
Or is there some other syntax reason for this error in the brackets?
error: expected identifier or '(' before '{' token
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#include <Iphlpapi.h>
#include <stdio.h>
#include "wclient.c"
#pragma comment(lib, "Ws2_32.lib")
int main()
{
int wsaserv;
WSADATA serv;
wsaserv = WSAStartup(MAKEWORD(2,2) , &serv);
return 0;
}
int servsock;
{
servsock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
}
struct sockaddr_in servaddr;
{
servaddr.sin_family = PF_INET;
servaddr.sin_addr.s_addr = INADDR_ANY;
servaddr.sin_port = htons(80)
memset(servaddr, 0, sizeof(servaddr));
};
int wire;
{
wire = listen(servsock, SOMAXCONN );
}
int srvb;
{
srvb = bind(servsock, (struct sockaddr *)&servaddr, sizeof(servaddr));
}
int prxy;
{
prxy = accept(servsock, (struct sockaddr *)&servaddr, sizeof(servaddr));
for(;;)
return 0;
}
int rs, sr;
{
rs = send(clisock, (struct sockaddr *)&cliserv, sizeof(cliserv), 0 );
sr = recv(clisock, (struct sockaddr *)&cliserv, sizeof(cliserv), 0 );
}
WSACleanup();
Here is the client side for linking:
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#include <winsock2.h>
#include <ws2tcpip.h>
#include <Iphlpapi.h>
#include <stdio.h>
#pragma comment(lib, "Ws2_32.lib")
int wsacli;
{
WSADATA cli;
wsacli = WSAStartup (MAKEWORD(2,2) , &cli);
}
int clisock;
{
clisock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
}
struct sockaddr_in cliserv;
{
cliserv.sin_family = PF_INET;
cliserv.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
cliserv.sin_port = htons(80);
memset(cliserv, 0, sizeof(cliserv));
};
int clcnct;
{
clcnct = connect(clisock, (struct sockaddr *)&cliserv, sizeof(cliserv));
}
int clcnct;
{
clibnd = bind(clisock, (struct sockaddr *)&cliserv, sizeof(cliserv));
}
int sc, rc;
{
sc = send(clisock, (struct sockaddr *)&cliserv, sizeof(cliserv), 0 );
rc = recv(clisock, (struct sockaddr *)&cliserv, sizeof(cliserv), 0 );
}
WSACleanup();
Windows PowerShell Copyright (C) Microsoft Corporation. All rights reserved.
Install the latest PowerShell for new features and improvements! https://aka.ms/PSWindows PS C:\Users\matt\Documents\Code-softwares> gcc wserver.c wclient.c lws2_32 In file included from wserver.c:8: wclient.c:18:1: error: expected identifier or '(' before '{' token 18 | { | ^ wclient.c:36:1: error: expected identifier or '(' before '{' token 36 | { | ^ wclient.c:47:1: error: expected identifier or '(' before '{' token 47 | { | ^ wclient.c:64:1: error: expected identifier or '(' before '{' token 64 | { | ^ wclient.c:76:1: error: expected identifier or '(' before '{' token 76 | { | ^ wclient.c:88:1: error: expected identifier or '(' before '{' token 88 | { | ^ wclient.c:99:2: warning: data definition has no type or storage class 99 | WSACleanup(); | ^~~~~~~~~~ wclient.c:99:2: warning: type defaults to 'int' in declaration of 'WSACleanup' [-Wimplicit-int] wclient.c:99:2: warning: 'WSACleanup' redeclared without dllimport attribute: previous dllimport ignored [-Wattributes] wserver.c:17:1: error: expected identifier or '(' before '{' token 17 | { | ^ wserver.c:69:1: error: expected identifier or '(' before '{' token 69 | { | ^ wserver.c:80:1: error: expected identifier or '(' before '{' token 80 | { | ^ wserver.c:93:1: error: expected identifier or '(' before '{' token 93 | { | ^ wserver.c:102:1: error: expected identifier or '(' before '{' token 102 | { | ^ wserver.c:111:1: error: expected identifier or '(' before '{' token 111 | { | ^ wserver.c:136:1: error: expected identifier or '(' before '{' token 136 | { | ^ wserver.c:150:2: warning: data definition has no type or storage class 150 | WSACleanup(); | ^~~~~~~~~~ wserver.c:150:2: warning: type defaults to 'int' in declaration of 'WSACleanup' [-Wimplicit-int] wclient.c:18:1: error: expected identifier or '(' before '{' token 18 | { | ^ wclient.c:36:1: error: expected identifier or '(' before '{' token 36 | { | ^ wclient.c:47:1: error: expected identifier or '(' before '{' token 47 | { | ^ wclient.c:64:1: error: expected identifier or '(' before '{' token 64 | { | ^ wclient.c:76:1: error: expected identifier or '(' before '{' token 76 | { | ^ wclient.c:88:1: error: expected identifier or '(' before '{' token 88 | { | ^ wclient.c:99:2: warning: data definition has no type or storage class 99 | WSACleanup(); | ^~~~~~~~~~ wclient.c:99:2: warning: type defaults to 'int' in declaration of 'WSACleanup' [-Wimplicit-int] wclient.c:99:2: warning: 'WSACleanup' redeclared without dllimport attribute: previous dllimport ignored [-Wattributes] PS C:\Users\matt\Documents\Code-softwares>