Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
GetRequest
//gcc 5.0.4 #import <Foundation/Foundation.h> #include <sys/socket.h> #include <netdb.h> #include <string.h> #define HTTP 80 int main(void) { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; char host[256]; gethostname(host, sizeof(host)); NSLog(@"Host Name: %s\n", host); struct addrinfo hints, *results, *t; memset(&hints, 0, sizeof(hints)); hints.ai_family = AF_INET; hints.ai_socktype = SOCK_STREAM; hints.ai_protocol = IPPROTO_TCP; getaddrinfo(host, NULL, &hints, &results); for (t= results; t; t = t->ai_next) { struct sockaddr_in *addr = (struct sockaddr_in*)t->ai_addr; char ip[INET_ADDRSTRLEN]; inet_ntop(t->ai_family, &(addr->sin_addr), ip, sizeof(ip)); NSLog(@"%s\n", ip); int sfd = socket(t->ai_family, t->ai_socktype, t->ai_protocol); if (sfd == -1) { NSLog(@"Error\n"); } struct sockaddr_in s_addr; memset(&s_addr, 0, sizeof(s_addr)); s_addr.sin_family = addr->sin_family; s_addr.sin_addr = addr->sin_addr; s_addr.sin_port = htons(HTTP); if (connect(sfd, (struct sockaddr*)&s_addr, sizeof(s_addr)) == -1) { NSLog(@"C Error\n"); } char req[1024]; sprintf(req, "GET /Default.aspx HTTP 1.0\r\nHost: %s\r\n\r\n", host); send(sfd, req, strlen(req), 0); char data[2056]; recv(sfd, data, sizeof(data), 0); NSLog(@"%s\n", data); } [pool drain]; return 0; }
run
|
edit
|
history
|
help
0
if con boleanos 01
asdfghjk
bookinheritence
find maximum in objective c
Inheritance Example
string divison
string mutable
objective c find factorial
Simple Arithmetic Operations in Objective C
Class implementation using get method