Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Winsock C TCP Socket

I've worked with TCP sockets before in Python. It looks pretty similar in C but I can't get anything to work. socket(AF_INET, SOCK_STREAM, 0); returns -1, which of course indicates an error. How could I go so wrong so fast? If you could help me with this problem, that would be nice, but it would be incredibly helpful if you could provide me with some simple, bare bones source code. It doesn't need to even do anything really, and it doesn't need to handle errors. I just need to see how to properly create a server socket, bind it, listen on it, and accept clients and how to create and connect a client socket. I can figure out all the bells and whistles on my own.

Thanks!

like image 416
Void Star Avatar asked Dec 01 '22 07:12

Void Star


1 Answers

Have you called WSAStartup before making any other winsock calls?

like image 173
Aaron Klotz Avatar answered Dec 04 '22 15:12

Aaron Klotz