Hello all, Im new to winsock, and Im having troubles with my C client. It is just intended for basic connectivity as of now. The code compiles fine, but when i run it, i never get it to display the "connected to the server" message, meaning it doesnt connect. Heres the code, and thanks!
Code:
/* Winsock Simple client code ( attempt anyway )*/
/* By Jay_Tech */
#include <stdio.h>
#include <winsock.h>
main()
{
WSADATA WsaDat;
if (WSAStartup(MAKEWORD(1, 1), &WsaDat) != 0)
{
printf("WSA Initialization failed!\n");
WSACleanup();
}
else printf("Winsock initialized!\n");
SOCKET Socket;
Socket= socket(AF_INET,SOCK_STREAM,0);
if(Socket== INVALID_SOCKET)
{
printf("Attempt to create socket failed!\n");
}
else printf("Socket created successfully!\n");
printf("Attempting to connect to host...\n");
/* Address and port info */
SOCKADDR_IN SockAddr;
SockAddr.sin_port= htons(6666);
SockAddr.sin_family= AF_INET;
SockAddr.sin_addr.s_addr= inet_addr("twisted.dal.net");
//inet_addr("twisted.dal.net");
if (connect(Socket,(SOCKADDR*)(&SockAddr), sizeof(SockAddr))!=0)
{
printf("Attempt to connect to host failed!\n");
}
else printf("Connected to host.\n");
WSACleanup();
return 0;
}
[edit]Code tags added by Hammer