Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
misc
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
misc
Commits
29a5c941
Commit
29a5c941
authored
May 05, 2016
by
Elvis Pranskevichus
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #4 from gallir/master
A simpler and perhaps faster server
parents
eb6e8940
ab01099e
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
40 deletions
+29
-40
servers/goecho.go
servers/goecho.go
+29
-40
No files found.
servers/goecho.go
View file @
29a5c941
...
...
@@ -3,44 +3,33 @@
package
main
import
(
"fmt"
"net"
"strconv"
"fmt"
)
const
PORT
=
25000
func
main
()
{
server
,
err
:=
net
.
Listen
(
"tcp"
,
":"
+
strconv
.
Itoa
(
PORT
))
server
,
err
:=
net
.
Listen
(
"tcp"
,
":"
+
strconv
.
Itoa
(
PORT
))
if
server
==
nil
{
panic
(
"couldn't start listening: "
+
err
.
Error
())
}
conns
:=
clientConns
(
server
)
for
{
go
handleConn
(
<-
conns
)
}
}
func
clientConns
(
listener
net
.
Listener
)
chan
net
.
Conn
{
ch
:=
make
(
chan
net
.
Conn
)
i
:=
0
go
func
()
{
for
{
client
,
err
:=
listen
er
.
Accept
()
client
,
err
:=
serv
er
.
Accept
()
if
client
==
nil
{
fmt
.
Printf
(
"couldn't accept: "
+
err
.
Error
())
continue
}
i
++
fmt
.
Printf
(
"%d: %v <-> %v
\n
"
,
i
,
client
.
LocalAddr
(),
client
.
RemoteAddr
())
ch
<-
client
go
handleConn
(
client
)
}
}()
return
ch
}
func
handleConn
(
client
net
.
Conn
)
{
defer
client
.
Close
()
buf
:=
make
([]
byte
,
102400
)
for
{
reqLen
,
err
:=
client
.
Read
(
buf
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment