Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
P
PySocket
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
Ergün Elvan Bilsel
PySocket
Commits
2a009d50
Kaydet (Commit)
2a009d50
authored
Tem 29, 2019
tarafından
Ergün Elvan Bilsel
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
Add new file
üst
0a533ae7
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
129 additions
and
0 deletions
+129
-0
server.py
server.py
+129
-0
No files found.
server.py
0 → 100644
Dosyayı görüntüle @
2a009d50
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import
tkinter
as
tk
from
datetime
import
datetime
import
socket
import
threading
import
freeport
from
psutil
import
process_iter
from
signal
import
SIGTERM
root
=
tk
.
Tk
()
root
.
title
(
"Server"
)
text
=
tk
.
Text
(
master
=
root
)
text
.
pack
(
expand
=
True
,
fill
=
"both"
)
entry
=
tk
.
Entry
(
master
=
root
)
entry
.
pack
(
expand
=
True
,
fill
=
"x"
)
frame
=
tk
.
Frame
(
master
=
root
)
frame
.
pack
()
def
buttons
():
for
i
in
"Baglan"
,
"Yolla"
,
"temizle"
,
"Exit"
,
"kopart"
,
"Client Listele"
:
b
=
tk
.
Button
(
master
=
frame
,
text
=
i
)
b
.
pack
(
side
=
"left"
)
yield
b
b1
,
b2
,
b3
,
b4
,
b5
,
b6
,
=
buttons
()
## b6 tanımlanacak
## b5 deneyseldir
class
Server
:
clients
=
[]
def
__init__
(
self
):
self
.
s
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
def
baglan
(
self
):
self
.
s
.
bind
((
""
,
9032
))
self
.
s
.
listen
(
10
)
now
=
str
(
datetime
.
now
())[:
-
7
]
text
.
insert
(
"insert"
,
"({}) : baglandı.
\n
"
.
format
(
now
))
self
.
condition
()
def
accept
(
self
):
c
,
addr
=
self
.
s
.
accept
()
self
.
clients
.
append
(
c
)
data
=
c
.
recv
(
1024
)
text
.
insert
(
"insert"
,
"({}) : {} sunucuya baglandı.
\n
"
.
format
(
str
(
datetime
.
now
())[:
-
7
],
str
(
data
)[
1
:]))
def
receive
(
self
):
for
i
in
self
.
clients
:
def
f
():
data
=
str
(
i
.
recv
(
1024
))[
2
:
-
1
]
now
=
str
(
datetime
.
now
())[:
-
7
]
if
len
(
data
)
==
0
:
pass
else
:
text
.
insert
(
"insert"
,
"({}) : {}
\n
"
.
format
(
now
,
data
))
t1_2_1
=
threading
.
Thread
(
target
=
f
)
t1_2_1
.
start
()
def
condition
(
self
):
while
True
:
t1_1
=
threading
.
Thread
(
target
=
self
.
accept
)
t1_1
.
daemon
=
True
t1_1
.
start
()
t1_1
.
join
(
1
)
t1_2
=
threading
.
Thread
(
target
=
self
.
receive
)
t1_2
.
daemon
=
True
t1_2
.
start
()
t1_2
.
join
(
1
)
def
yolla
(
self
):
respond
=
format
(
str
(
entry
.
get
()))
now
=
str
(
datetime
.
now
())[:
-
7
]
entry
.
delete
(
"0"
,
"end"
)
try
:
for
i
in
self
.
clients
:
i
.
sendall
(
bytes
(
respond
.
encode
(
"utf-8"
)))
text
.
insert
(
"insert"
,
"({}) : {}
\n
"
.
format
(
now
,
respond
))
except
BrokenPipeError
:
text
.
insert
(
"insert"
,
"({}) : Client has been disconnected.
\n
"
.
format
(
now
))
def
kopart
(
self
):
for
proc
in
process_iter
():
for
conns
in
proc
.
connections
(
kind
=
'inet'
):
if
conns
.
laddr
.
port
==
9032
:
proc
.
send_signal
(
SIGTERM
)
s1
=
Server
()
def
baglan
():
t1
=
threading
.
Thread
(
target
=
s1
.
baglan
)
t1
.
start
()
def
yolla
():
t2
=
threading
.
Thread
(
target
=
s1
.
yolla
)
t2
.
start
()
def
temizle
():
text
.
delete
(
"1.0"
,
"end"
)
def
kopart
():
t3
=
threading
.
Thread
(
target
=
s1
.
kopart
)
t3
.
start
()
def
destroy
():
root
.
destroy
()
exit
()
if
__name__
==
"__main__"
:
b1
.
configure
(
command
=
baglan
)
b2
.
configure
(
command
=
yolla
)
b3
.
configure
(
command
=
temizle
)
b4
.
configure
(
command
=
destroy
)
b5
.
configure
(
command
=
kopart
)
t0
=
threading
.
Thread
(
target
=
root
.
mainloop
)
t0
.
run
()
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