-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from timmy61109/feature/v0.1.1-pytalk+timmy61109
PyTalk 修改項目: - 可匯入也可直接執行的主程式 - 完成核心並提供直接取用 - 加入可以使用套件、外掛、插件的功能
- Loading branch information
Showing
8 changed files
with
123 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#!/usr/bin/python | ||
# -*- coding: utf-8 -*- | ||
# coding = UTF-8 | ||
from .Communication import tcp | ||
|
||
tcp = tcp() | ||
|
||
|
||
class talk(): | ||
def __init__(self): | ||
self.version = "0.0.1" | ||
|
||
def accept_message(self, host="0.0.0.0", port=5000, charset="utf8", | ||
end_of_message=True): | ||
data = tcp.server(Host=host, Port=port, | ||
Charset=charset, end_of_message=end_of_message) | ||
while True: | ||
message = next(data) | ||
if message == "None": | ||
yield None | ||
break | ||
else: | ||
yield message | ||
|
||
def send_message(self, host="127.0.0.1", port=5000, charset="utf8"): | ||
while True: | ||
message = str(input("You:")) | ||
tcp.client(Host=host, Port=port, | ||
message=message, Charset=charset) | ||
if message == "None": | ||
yield None | ||
break | ||
else: | ||
yield True |
File renamed without changes.
File renamed without changes.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
#!/usr/bin/python | ||
# -*- coding: utf-8 -*- | ||
# coding = UTF-8 | ||
from Core.Talk import talk | ||
from argparse import ArgumentParser | ||
|
||
talk = talk() | ||
|
||
|
||
class pytalk(): | ||
def __init__(self, mode="client", | ||
host="127.0.0.1", | ||
port=5000, | ||
charset="utf8", | ||
end_of_message=True): | ||
self.mode = mode | ||
if mode != "client" and mode != "server": | ||
raise ValueError('Not is client or server') | ||
|
||
self.accept_message = talk.accept_message( | ||
host=host, port=port, charset=charset, | ||
end_of_message=end_of_message) | ||
|
||
self.send_message = talk.send_message(host=host, | ||
port=port, | ||
charset=charset) | ||
|
||
def accept(self): | ||
while True: | ||
print(next(self.accept_message)) | ||
|
||
def send(self): | ||
while True: | ||
next(self.send_message) | ||
|
||
@property | ||
def runtalk(self): | ||
if self.mode == "client": | ||
self.send() | ||
elif self.mode == "server": | ||
self.accept() | ||
|
||
|
||
if __name__ == '__main__': | ||
parser = ArgumentParser() | ||
|
||
parser.add_argument('-m', '--mode', default='client', | ||
type=str, | ||
help="Use mode server or client, default is client", | ||
dest="mode") | ||
|
||
parser.add_argument('-s', '--server', default='127.0.0.1', | ||
type=str, | ||
help="Host name or IP address of your server.", | ||
dest="host") | ||
|
||
parser.add_argument('-p', '--port', default=2000, | ||
type=int, | ||
help='Port number of your server.', | ||
dest="port") | ||
|
||
parser.add_argument( | ||
'--end_of_message', default=True, | ||
type=bool, | ||
help='When the message is the end command, used for the server.', | ||
dest='end_of_message' | ||
) | ||
|
||
parser.add_argument('--charset', default="utf8", | ||
type=str, | ||
help='Encoding format.', | ||
dest='charset' | ||
) | ||
|
||
args = parser.parse_args() | ||
|
||
pytalk = pytalk(mode=args.mode, host=args.host, port=args.port, | ||
charset=args.charset, end_of_message=args.end_of_message) | ||
pytalk.runtalk |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.