Created
December 31, 2016 11:19
-
-
Save mpfund/ffa6c4a4e8bbbf53ce66469a8021ddb3 to your computer and use it in GitHub Desktop.
sockets in C
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int main() | |
{ | |
SOCKET sock; | |
sockaddr_in target; | |
unsigned long addr; | |
WSADATA wsaData; | |
WSAStartup(MAKEWORD(2,0),&wsaData); | |
target.sin_family = AF_INET; | |
target.sin_port = htons(80); | |
addr = inet_addr("127.0.0.1"); | |
memcpy((char *)&target.sin_addr,&addr,sizeof(addr)); | |
sock = socket(AF_INET,SOCK_STREAM,0); | |
if (connect(sock,(struct sockaddr*)&target,sizeof(target))<0) | |
{printf("Fehler");} | |
else | |
{ | |
printf("Connection etablished"); | |
char texttosend[40] = "Gehts ??"; | |
send(sock,texttosend,sizeof(texttosend),0); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment