Quantcast
Channel: Programming Forums
Viewing all articles
Browse latest Browse all 51036

Dev-C++ (Bloodshed) - Socket Server

$
0
0
I'm having a few difficulties making a socket server via Dev-C++ (Bloodshed).
Throughout this page, i'll also include images to support what I'm doing.
First off,
I was testing out a small application for a very basic "You're connected" code.
So here we go, The code that I currently have:
#include <sdkddkver.h>
#include <conio.h>
#include <stdio.h>

#include <WinSock2.h>
#include <Windows.h>
#include <iostream>

#include <string>

using namespace std;

bool connected = false;

int main() {
	string sentmessage;

	long answer;
	WSAData wsaData;
	WORD DLLVERSION;
	DLLVERSION = MAKEWORD(2,1);
	answer = WSAStartup(DLLVERSION, &wsaData);

	SOCKADDR_IN addr;
	int addrlen = sizeof(addr);

	SOCKET sListen;
	SOCKET sConnect;

	sConnect = socket(AF_INET,SOCK_STREAM,NULL);

	addr.sin_addr.s_addr = inet_addr("127.0.0.1");
	addr.sin_family = AF_INET;
	addr.sin_port = htons(1234);

	sListen = socket(AF_INET,SOCK_STREAM,NULL);
	bind(sListen, (SOCKADDR*)&addr, sizeof(addr));
	listen(sListen, SOMAXCONN);

	cout << "Waiting for an incoming conection..." << endl;

	for (;;)/> {
		if (sConnect = accept(sListen, (SOCKADDR*)&addr, &addrlen)) {
			if (connected == false) {
				cout << "A connection has been found!";
			    answer = send(sConnect, "YourMessage", 12, NULL);
				connected = true;
			}
			answer = send(sConnect, "Hey", 4, NULL);
		}
	}
}

Looks fine to me!
Nope.
Here are a few errors i'm recieving:

Yes, I do have libws2_32.a linked in paramaters as well:

Not sure what else i'm forgetting to talk about and/or show.
So, just comment if you're trying to help and need more info =D
All help is appreciated.

Viewing all articles
Browse latest Browse all 51036

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>