Pip install socket python

socket.py 0.1.0

История выпусков Уведомления о выпусках | Лента RSS

Загрузка файлов

Загрузите файл для вашей платформы. Если вы не уверены, какой выбрать, узнайте больше об установке пакетов.

Source Distribution

Uploaded 18 авг. 2019 г. source

Built Distribution

Uploaded 18 авг. 2019 г. py3

Хеши для socket.py-0.1.0.tar.gz

Хеши для socket.py-0.1.0.tar.gz
Алгоритм Хеш-дайджест
SHA256 08ded821472d38dbfbf233d0cc77be277e557fb141bf8a744de1b2992a86d5a5 Копировать
MD5 a61335cc7641da7b64fa76ea7df97e47 Копировать
BLAKE2b-256 c4ff17e5109c257211d8d23b38dd64d8b1159fdef02e77d228a31582e1ad22c0 Копировать

Хеши для socket.py-0.1.0-py3-none-any.whl

Хеши для socket.py-0.1.0-py3-none-any.whl
Алгоритм Хеш-дайджест
SHA256 74c331945a0a77c934fb4903413e6f9da4f53523383581c98a3eece6345cd6ac Копировать
MD5 400f383f2ffdfc518dc52a4e6ac55bfd Копировать
BLAKE2b-256 c13036092145059856bcea7a13654418266228be96c173455027867350f75c36 Копировать

Помощь

О PyPI

Внесение вклада в PyPI

Использование PyPI

Разработано и поддерживается сообществом Python’а для сообщества Python’а.
Пожертвуйте сегодня!

PyPI», «Python Package Index» и логотипы блоков являются зарегистрированными товарными знаками Python Software Foundation.

Источник

How to install socket-for-humans via python pip

socket-for-humans — A simplified TCP/IP socket setup suitable for many/most lightweight client server programs. The python standard library `socket` module has a relatively steep learning curve. The `socket_for_humans` module will help get most projects up and running quickly by wrapping the Python standard library socket module in an easy to use interface., it belongs to Classifiers:

When you know about this project and you want to new install socket-for-humans to support your project or you get trouble as ModuleNotFoundError: No module named «socket-for-humans» or ImportError: cannot import name «socket-for-humans» in your project, let follow this tutorial to install socket-for-humans

Installation:

Step 1: First, ensure you installed pip in your os, to check pip has been installed on your computer

Ensure pip, setuptools, and wheel are up to date:

py -m pip install --upgrade pip setuptools wheel
python3 -m pip install --upgrade pip setuptools wheel

Optional — If you want to install

Читайте также:  All in one events calendar css

— Install virtualenv — if you installed it, please ignore

py -m pip install --user virtualenv

— Create a virtual environment

py -m venv test_socket-for-humans_env

— Active the virtual environment

test_socket-for-humans_env\Scripts\active

— Install virtualenv — if you installed it, please ignore

— Create a virtual environment

python3 -m venv test_socket-for-humans_env

— Active the virtual environment

source test_socket-for-humans_env/bin/active

Step 2: OK, now, let flow below content to start the installation socket-for-humans

To install socket-for-humans on Windows(CMD):

py -m pip install socket-for-humans

To install socket-for-humans on Unix/macOs:

pip install socket-for-humans

Step 3: If you want to install a specific socket-for-humans version, add == to the end command line

pip install socket-for-humans==0.0.1

Please see the version list below table:

py -m pip install socket-for-humans==0.0.3
pip install socket-for-humans==0.0.3
py -m pip install socket-for-humans==0.0.2
pip install socket-for-humans==0.0.2
py -m pip install socket-for-humans==0.0.1
pip install socket-for-humans==0.0.1

Step 4: Otherwise, you can install socket-for-humans from local archives:

Download the distribution file from socket_for_humans-0.0.3.tar.gz or the specific socket-for-humans version in the below list of distribution

After that, install by command:

Источник

Real-Time Desktop chat application using Python

socket is used to establish the connection between two systems, as we are performing two tasks simultaneously we need threading to create a separate thread for each task, and Tkinter is used to create our GUI, lets start by creating the Gui

root=Tk() root.geometry("300x500") root.config(bg="white") startchatimage=PhotoImage(file='start.png') buttons=Button(root,image=startchatimage,command=func,borderwidth=0) buttons.place(x=90,y=10) message=StringVar() messagebox=Entry(root,textvariable=message,font=('calibre',10,'normal'),border=2,width=32) messagebox.place(x=10,y=444) sendmessageimg=PhotoImage(file='send.png') sendmessagebutton=Button(root,image=sendmessageimg,command=threadsendmsg,borderwidth=0) sendmessagebutton.place(x=260,y=440) lstbx=Listbox(root,height=20,width=43) lstbx.place(x=15,y=80) user_name = Label(root,text =" Number" ,width=10) root.mainloop()

We are initializing our Tkinter window by creating Tk class instance with the variable name root, then we are specifying what is the geometry or what is the height and width of GUI then we are specifying the background color of our GUI, we have 5 widgets in our Gui (You can download the images from our GitHub repository ) let’s create them one by one

  • Start chat Button : this buttton will be used to connect two user for chat, lets see how we can create it, startchatimage variable will store the image data by using PhotoImage() class of tkinter parameter being the image path,then we will create the button using Button class with following parameters
    • tkinter class instance
    • image on the button (you can also define text here)
    • command(function) that this button will trigger
    • width of the border of the button

    startbutton is then placed using place class parameters are x and y coordinates at which you want to place the button

    • message box : this is small rectangular text area where we will write text that we want to send, this is basically a entry widget with following parameters
      • tkinter class instance
      • text variable
      • font size and style
      • border width
      • width of entry box

      message box is then placed at desired x and y coordinates

      • Send message Button : This button is pressed when user wants to send the message paramters are same as start button with a few changes
        • function triggered is different
        • button image is different
        • coordinate at which button to be placed is different
        • Message Box : This is where all the messages will appear from both the users its a listbox widget with following parameters
          • tkinter class instance
          • height and width of listbox

          lastly, we will close the mainloop as our GUI is completed, after completing the frontend let’s jump backstage and complete what’s happening behind.

          def func(): t=threading.Thread(target=recv) t.start()

          to start the connection we press the start chat button that we have already discussed above in the frontend part, this button will trigger func() function, this function will create a separate thread that will continuously run in the background checking for new incoming messages, target for this thread is recv function, now lets see what inside this recv() function

          def recv(): listensocket=socket.socket() port=3050 maxconnection=99 ip=socket.gethostname() print(ip) listensocket.bind(('',port)) listensocket.listen(maxconnection) (clientsocket,address)=listensocket.accept() while True: sendermessage=clientsocket.recv(1024).decode() if not sendermessage=="": time.sleep(5) lstbx.insert(0,"Client : "+sendermessage)

          first, we create a socket instance with the variable name listensocket, port value is the port number of the system you want to chat with, maxconnection is the maximum number of incoming connections, ip will store the host ip which we will use to connect on another system after the connection is received we will bind it with our system using the port number of the second system, we are listening to the connection up to a maximum limit defined by maxconnection variable, after this, we are finally accepting the incoming signal with client socket and address, now to keep this constantly running we are running an infinite while loop inside which we will first decode the message and if the message is not empty we will add time delay of 5 seconds and then insert the message into our listbox, soo this was how we can receive the messages now lets see how we can send one

          def threadsendmsg(): th=threading.Thread(target=sendmsg) th.start()

          In the frontend section, we created the entry widget and send button so the send button will trigger threadsendmsg() function which will create a separate thread for sending messages and we will do that inside sendmsg function

          s=0 def sendmsg(): global s if s==0: s=socket.socket() hostname='' port=4050 s.connect((hostname,port)) msg=messagebox.get() lstbx.insert(0,"You : "+msg) s.send(msg.encode()) else: msg=messagebox.get() lstbx.insert(0,"You : "+msg) s.send(msg.encode())

          we will first create a variable outside the function this variable will be used to run a few instructions only once which I will explain later in this paragraph only, inside the function we will call the variable from outside and check if the value is equal to 0 and if it is we will create socket instance define the port and connect with the system after this we will extract the data from our entry widget using .get() command and after inserting the message in the Listbox to make it look like a chat between two people we will send the message to the connected system so these commands will run when the value of s=0 now if you look closely we are using s variable for socket also so this means after the first time variable is not 0 so else condition will be executed from now, inside else we have everything same except the connection is already established so we will simply get the message from entry box insert in Listbox and send it to receiver

          The exact same program is present on the second system also only with a few changes

          for a more detailed explanation watch this video

          Complete Code

          import socket import time import threading from tkinter import * root=Tk() root.geometry("300x500") root.config(bg="white") def func(): t=threading.Thread(target=recv) t.start() def recv(): listensocket=socket.socket() port=3050 maxconnection=99 ip=socket.gethostname() print(ip) listensocket.bind(('',port)) listensocket.listen(maxconnection) (clientsocket,address)=listensocket.accept() while True: sendermessage=clientsocket.recv(1024).decode() if not sendermessage=="": time.sleep(5) lstbx.insert(0,"Client : "+sendermessage) s=0 def sendmsg(): global s if s==0: s=socket.socket() hostname='' port=4050 s.connect((hostname,port)) msg=messagebox.get() lstbx.insert(0,"You : "+msg) s.send(msg.encode()) else: msg=messagebox.get() lstbx.insert(0,"You : "+msg) s.send(msg.encode()) def threadsendmsg(): th=threading.Thread(target=sendmsg) th.start() startchatimage=PhotoImage(file='start.png') buttons=Button(root,image=startchatimage,command=func,borderwidth=0) buttons.place(x=90,y=10) message=StringVar() messagebox=Entry(root,textvariable=message,font=('calibre',10,'normal'),border=2,width=32) messagebox.place(x=10,y=444) sendmessageimg=PhotoImage(file='send.png') sendmessagebutton=Button(root,image=sendmessageimg,command=threadsendmsg,borderwidth=0) sendmessagebutton.place(x=260,y=440) lstbx=Listbox(root,height=20,width=43) lstbx.place(x=15,y=80) user_name = Label(root,text =" Number" ,width=10) root.mainloop()

          Источник

Оцените статью