EasyManua.ls Logo

STW TC1 - Page 53

STW TC1
374 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
6 Software
User Manual 53/374
struct sockaddr_in t_Srv;
memset(&t_Srv, 0, sizeof(struct sockaddr_in));
t_Srv.sin_family = AF_INET;
inet_pton(AF_INET, "1.2.3.4", &t_Srv.sin_addr); // Set server IP to struct sockaddr_in
t_Srv.sin_port = htons(1234); // Set port in Network-Byte-Order (Big Endian) to sin_port
s16_Return = connect(s16_Sockfd, (struct sockaddr*)&t_Srv, sizeof(struct sockaddr_in)); //
Try to connect
if(s16_Return == 0)
{
// TCP connection is established. Now write() and read() could be used to to write or read
sockets
[...] // Data handling
shutdown(s16_Sockfd, SHUT_WR); // Send a EOF-Byte to the server, so that on the next read()
we will get a 0-return and we could close the connection
close(s16_Sockfd);

Table of Contents