@@ -42,7 +42,7 @@ The `net` package in Go provides many types, functions and methods for network p
|
||||
|
||||
type IP []byte
|
||||
|
||||
Functions `ParseIP(s string) IP` is for converting an IP from the IPv4 format into IPv6:
|
||||
Function `ParseIP(s string) IP` is to convert the IPv4 or IPv6 format to an IP:
|
||||
|
||||
package main
|
||||
import (
|
||||
@@ -297,7 +297,7 @@ Some of you may be thinking the following: this server does not do anything mean
|
||||
}
|
||||
}
|
||||
|
||||
In this example, we use `conn.Read()` to constantly read client requests. We cannot close the connection because clients may issue more than one request. Due to the timeout we set using `conn.SetReadDeadline()`, the connection closes automatically when a client has not sent a request within our allotted time period. When then expiry time has elapsed, our program breaks from the `for` loop. Notice that `request` needs to be created with a max size limitation in order to prevent flood attacks. FInally, we clean the `request` array after processing every request, since `conn.Read()` appends new content to the array instead of rewriting it.
|
||||
In this example, we use `conn.Read()` to constantly read client requests. We cannot close the connection because clients may issue more than one request. Due to the timeout we set using `conn.SetReadDeadline()`, the connection closes automatically when a client has not sent a request within our allotted time period. When then expiry time has elapsed, our program breaks from the `for` loop. Notice that `request` needs to be created with a max size limitation in order to prevent flood attacks. Finally, we clean the `request` array after processing every request, since `conn.Read()` appends new content to the array instead of rewriting it.
|
||||
|
||||
### Controlling TCP connections
|
||||
|
||||
|
||||
Reference in New Issue
Block a user