FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Python/socket-programming/server.py at master · popdeveloper/Python · GitHub
popdeveloper
/
Python
Public
forked from
geekcomputers/Python
Notifications
You must be signed in to change notification settings
Fork
0
Star
1
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Python
/
socket-programming
/
server.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
35 lines (34 loc) · 1.22 KB
Breadcrumbs
Python
/
socket-programming
/
server.py
Copy path
File metadata and controls
35 lines (34 loc) · 1.22 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# import socket module
import
socket
# create TCP/IP socket
s
=
socket
.
socket
()
# get the according IP address
ip_address
=
socket
.
gethostbyname
(
socket
.
gethostname
())
# binding ip address and port
s
.
bind
((
ip_address
,
12345
))
# listen for incoming connections (server mode) with 3 connection at a time
s
.
listen
(
3
)
# print your ip address
print
(
"Server ip address:"
,
ip_address
)
while
True
:
# waiting for a connection establishment
print
(
'waiting for a connection'
)
connection
,
client_address
=
s
.
accept
()
try
:
# show connected client
print
(
'connected from'
,
client_address
)
# sending acknowledgement to client that you are connected
connection
.
send
(
str
(
"Now You are connected"
).
encode
(
"utf-8"
))
# receiving the message
while
True
:
data
=
connection
.
recv
(
1024
).
decode
(
"utf-8"
)
if
data
:
# message from client
print
(
list
(
client_address
)[
0
],
end
=
""
)
print
(
": %s"
%
data
)
# Enter your message to send to client
new_data
=
str
(
input
(
"You: "
)).
encode
(
"utf-8"
)
connection
.
send
(
new_data
)
finally
:
# Close connection
connection
.
close
()
Back
|
FazBrowse Home
|
New Git URL