Folge dem Video um zu sehen, wie unsere Website als Web-App auf dem Startbildschirm installiert werden kann.
Anmerkung: Diese Funktion ist in einigen Browsern möglicherweise nicht verfügbar.
#include <iostream>
#include <stdio.h>
#include <errno.h>
#include <string>
/* Windows */
#ifdef _WIN32
#include <winsock.h>
/* Unix */
#else
#include <sys/socket.h>
#include <sys/types.h>
#inlcude <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <unistd.h>
#endif
using namespace std;
int main()
{
#ifdef _WIN32
WSADATA wsaData;
if(WSAStartup (MAKEWORD(1,1), &wsaData) != 0)
{
fprintf(stderr, "WSAStartup(): Kann Winsock nicht initialisieren. \n");
exit(EXIT_FAILURE);
}
#endif
int sockfd = socket(AF_INET, SOCK_STREAM, 0);
if(sockfd == -1)
perror("socket()");
char command[1024];
int bytes_send;
sockaddr_in my_addr;
my_addr.sin_family = AF_INET;
my_addr.sin_port = htons(22322);
my_addr.sin_addr.s_addr = htonl(INADDR_ANY);;
if(bind(sockfd, (sockaddr *) &my_addr, sizeof(sockaddr)) == -1)
perror("bind()");
if (listen(sockfd, 5) == -1)
perror("listen()");
int sin_size = sizeof(sockaddr_in);
int sock2 = accept(sockfd, (sockaddr *) &my_addr, &sin_size);
int i = 0;
if(sock2 == -1) {
perror("accept()");
exit(EXIT_FAILURE);
}
string text = "Testnachricht";
const char *p = text.c_str();
strcpy(command, p);
bytes_send = send(sockfd, command, strlen(command), 0);
if(bytes_send == -1) {
perror("send()");
exit(EXIT_FAILURE);
}
#ifdef _WIN32
WSACleanup();
#endif
}
#include <iostream>
#include <stdio.h>
#include <errno.h>
#include <string>
#include <fstream>
/* Windows */
#ifdef _WIN32
#include <winsock.h>
/* Unix */
#else
#include <sys/socket.h>
#include <sys/types.h>
#inlcude <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <unistd.h>
#endif
using namespace std;
int main()
{
#ifdef _WIN32
WSADATA wsaData;
if(WSAStartup (MAKEWORD(1,1), &wsaData) != 0)
{
fprintf(stderr, "WSAStartup(): Kann Winsock nicht initialisieren. \n");
exit(EXIT_FAILURE);
}
#endif
int sockfd = socket(AF_INET, SOCK_STREAM, 0);
if(sockfd == -1)
perror("socket()");
int bytes_recv;
char buf[1024];
sockaddr_in serv_addr;
serv_addr.sin_family = AF_INET;
serv_addr.sin_port = htons(22322);
serv_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
if(connect(sockfd, (sockaddr *) &serv_addr, sizeof(sockaddr)) == -1)
perror("connect()");
ofstream outfile ("new.txt",ofstream::binary);
while((bytes_recv = recv(sockfd,buf, sizeof(buf), 0))>0) {
outfile.write(buf,bytes_recv);
cout << bytes_recv << endl;
}
if(bytes_recv == -1){
perror("recv()");
exit(EXIT_FAILURE);
}
int close(int fd);
#ifdef _WIN32
closesocket(sockfd);
WSACleanup();
#else
close(sockfd);
#endif
return 0;
}
Ja klarTja, Thommy, du musst noch einiges lernen. Da kann ich jetzt keine spezifisches Zeug dazu sagen, das wäre zu umfangreich.
Du lernst erst grade mal C++ und machst schon Server-Client Zeugs?