Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 06afe4f

Browse files
Added Some Documentation to C Socket Examples
The strange "0" in send and rcv stands for flags, which are 0.
1 parent 07defa3 commit 06afe4f

File tree

8 files changed

+8
-8
lines changed

8 files changed

+8
-8
lines changed

‎sockets/c/TCPClient_linux.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ int main(int argc, char *argv[]) {
1717
connect(client, (struct sockaddr *)&address, sizeof(address)); //(*@\clientBox{1+2)}@*)
1818

1919
data = 2;
20-
send(client, &data, 1, 0); //(*@\clientBox{3)}@*)
20+
send(client, &data, 1, 0); //(*@\clientBox{3)}@*) send 1 byte of data to client, flags=0
2121

2222
close(client); //(*@\clientBox{4)}@*)
2323
return 0;

‎sockets/c/TCPClient_windows.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ int main(int argc, char *argv[]) {
1616
connect(client, (struct sockaddr *)&address, sizeof(address)); //(*@\clientBox{1+2)}@*)
1717

1818
data = 2;
19-
send(client, &data, 1, 0); //(*@\clientBox{3)}@*)
19+
send(client, &data, 1, 0); //(*@\clientBox{3)}@*) send 1 byte of data to client, flags=0
2020

2121
closesocket(client); //(*@\clientBox{4)}@*)
2222
WSACleanup(); //Finalize WinSock

‎sockets/c/TCPServer_linux.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ int main(int argc, char *argv[]) {
2424
for (j = 5; (--j) >= 0;) {
2525
client = accept(server, (struct sockaddr *) &clientAddr, &addrSize); //(*@\serverBox{3)}@*)
2626
printf("New connection from %s\n", inet_ntoa(clientAddr.sin_addr));
27-
27+
// now receive 1 byte of data to client, flags=0
2828
if(recv(client, &data, 1, 0) == 1) { printf("%d\n", data); } //(*@\serverBox{4} + \clientBox{3})@*)
2929
close(client); //(*@\clientBox{4)}@*)
3030
}

‎sockets/c/TCPServer_windows.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ int main(int argc, char *argv[]) {
2121
for (j = 5; (--j) >= 0;) {
2222
client = accept(server, (struct sockaddr *) &clientAddr, &addrSize); //(*@\serverBox{3)}@*)
2323
printf("New connection from %s\n", inet_ntoa(clientAddr.sin_addr));
24-
24+
// now receive 1 byte of data to client, flags=0
2525
if(recv(client, &data, 1, 0) == 1) { printf("%d\n", data); } //(*@\serverBox{4} + \clientBox{3})@*)
2626
closesocket(client); //(*@\clientBox{4)}@*)
2727
}

‎sockets/c/UDPClient_linux.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ int main(int argc, char *argv[]) {
1414
address.sin_addr.s_addr = inet_addr("127.0.0.1");//Set to (loopback) IP address
1515
address.sin_port = htons(9998); //Make port in network byte order
1616

17-
data = 2;
17+
data = 2;// then send 1 byte package data to client, with flags=0
1818
sendto(client, &data, 1, 0, (struct sockaddr *)&address, sizeof(address)); //(*@\clientBox{1+2)}@*)
1919

2020
close(client); //(*@\clientBox{4)}@*)

‎sockets/c/UDPClient_windows.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ int main(int argc, char *argv[]) {
1313
address.sin_addr.s_addr = inet_addr("127.0.0.1");//Set to (loopback) IP address
1414
address.sin_port = htons(9998); //Make port in network byte order
1515

16-
data = 2;
16+
data = 2;// then send 1 byte package data to client, with flags=0
1717
sendto(client, &data, 1, 0, (struct sockaddr *)&address, sizeof(address)); //(*@\clientBox{1+2)}@*)
1818

1919
closesocket(client); //(*@\clientBox{4)}@*)

‎sockets/c/UDPServer_linux.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ int main(int argc, char *argv[]) {
1919
server = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP); //Allocate UDP socket
2020
bind(server, (struct sockaddr *) &serverAddr, sizeof(serverAddr)); //(*@\serverBox{1)}@*)
2121

22-
for (j = 5; (--j) >= 0;) {
22+
for (j = 5; (--j) >= 0;) {// then receive 1 byte package data and get client address, with flags=0
2323
recvfrom(server, &data, 1, 0, (struct sockaddr *) &clientAddr, &addrSize); //(*@\serverBox{2)}@*)
2424
printf("New message %d from %s\n", data, inet_ntoa(clientAddr.sin_addr)); //(*@\serverBox{3)}@*)
2525
}

‎sockets/c/UDPServer_windows.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ int main(int argc, char *argv[]) {
1717
server = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);//Allocate UDP socket
1818
bind(server, (struct sockaddr *) &serverAddr, sizeof(serverAddr)); //(*@\serverBox{1)}@*)
1919

20-
for (j = 5; (--j) >= 0;) {
20+
for (j = 5; (--j) >= 0;) {// then receive 1 byte package data and get client address, with flags=0
2121
recvfrom(server, &data, 1, 0, (struct sockaddr *) &clientAddr, &addrSize); //(*@\serverBox{2)}@*)
2222
printf("New message %d from %s\n", data, inet_ntoa(clientAddr.sin_addr)); //(*@\serverBox{3)}@*)
2323
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /