-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
55 additions
and
3 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
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,35 @@ | ||
"""Mojo TCP Socket Server with PythonInterface""" | ||
from PythonInterface import Python | ||
|
||
# Python Socket | ||
let socket = Python.import_module('socket') | ||
|
||
let host = socket.gethostbyname(socket.gethostname()).to_string() | ||
print(host) | ||
py_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | ||
|
||
py_socket.bind(("10.8.95.167", 55555)) | ||
print("Socket bind to", "10.8.95.167", 55555) | ||
|
||
py_socket.listen() | ||
print("Listen for client connection ..") | ||
|
||
var conn_addr = py_socket.accept() | ||
var conn = conn_addr[0] | ||
let addr = conn_addr[1] | ||
print("Connected by client", addr) | ||
|
||
while True: | ||
let data = conn.recv(1024) | ||
if data: | ||
print("Message from client", data) | ||
else: | ||
break | ||
# ping-pong | ||
conn.sendall(data) | ||
|
||
conn.close() | ||
print("Connection close.") | ||
|
||
py_socket.close() | ||
print("Socket close.") |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.