C programming, sockets/client-server.

Caporegime
Joined
12 Mar 2004
Posts
29,962
Location
England
I don't even know where to start with this exercise lol.

I have to create a client-server messaging program.

I've included the winsock.h header file and have got this statement: socket(PF_INET, SOCK_STREAM, 0), can't work out how to declare a socket though I've missed so much. I'd have thought it would be something like "socket sock; sock = socket(PF_INET, SOCK_STREAM, 0);" but the compiler doesn't seem to like that. Any suggestions?
 
Still can't get the most basic program to work lol.

This,
Code:
#include <stdio.h>
#include <stdlib.h>
#include <winsock.h>

int main(int argc, char * argv[]) {
	SOCKET sock;
	sock = socket(PF_INET, SOCK_STREAM, 0);
	system("pause");
	return 0;
}


keeps giving me the error message.

Code:
1>Main.obj : error LNK2019: unresolved external symbol _socket@12 referenced in function _main
1>C:\Users\Administrator\Documents\Visual Studio 2008\Projects\Chat\Debug\Chat.exe : fatal error LNK1120: 1 unresolved externals
 
Just to expand on the above really (it always takes me ages to find the correct section :p):

In Visual Studio (I'm using 2008, the rest should be similar)

  1. Go to project > properties
  2. Expand Configuration Properties
  3. Expand Linker
  4. Click Input
  5. Add 'ws2_32.lib' (no quotes) to 'Additional Dependencies'

and it'll compile :).


Thanks you two, finally got it to compile. :) Java is so much easier...
 
Back
Top Bottom