Python peer to peer chat

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

İt is a peer to peer chat application . it’s developed on python with socket library

altuntasfatih/p2p-chat-application

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

In this project we are operating peer to peer chatting using high level socket programming. Briefly, P2P chat is a chat method which provides send messages directly communicating with peers without using servers.

We have two main component which are Server (registry) and Client (peer).

Simply, on client side, user will send register request to register himself into Server, after registering also user will send login request to login Server. After login processes user will be able to chat with other peers.

On server side, server has ability to accept and reject requests which comes from the users. If user logins in successfully, server will send online user list to user. And user will see online users to start chat.

Also server and client has different functionalities like checking and sending “hello” messages, etc.

Читайте также:  Reading last line python

We need to do more than one job at the same time. Therefore we are implementing multi- thread system.

On server side , we are using MongoDB to manage and store data. There are TCP socket which listens port 3131 and UDP socket which listens 5151. We are starting a thread for each user who wants to communicate with server to listen TCP socket and handle requests. These threads are working until user are logged out or ends to application. And we are starting one more thread to listen UDP socket and catch “hello” messages which comes from peers.

On client side , after login process, user starts a channel between himself and server. By using this channel, he makes server operations like sending request and sending “hello”

Also client has two main thread. First one is listening the chat requests which comes from other peers. Second thread is for get messages from peers and print these messages to chat screen.

Client has a data structure ( chat_list ). If other peers accept our chat request, the peer who sent the request add the user he want to communicate with into chat_list. If user wants to send a message, message will be sent everyone in the chat_list.

We have 5 type request between server and client:

  • Register : In data part, we are sending “password”.
  • Login: In data part, we are sending “password”.
  • Search: In data part, we are sending the username which we want to search. We never use the request. Instead of we used “all online”.
  • Logout: In data part, we are sending ‘LOGOUT’ message.
  • All Online: In data part, we are sending ‘All’ message.

screen shot 2017-12-19 at 00 38 39

We have 2 different package type between client and client:

  • Message package:
    Type will be 0
    Type (b)
    Username (10s)
    Message (100s)
  • Notify and Request:
    In Notify, type will be “1”, Message will be “New User” and Data will be IP address. Also we are sending current chat_list to handle group chat. If new user appears, old users will be informed.
    In Request, type will be “0”, Message will be “CHAT REQUEST” and Data will be username.
    Type will be 1
    Type (b)
    Data (15s)
    Message (10s)
    chat_list

screen shot 2017-12-19 at 00 48 02

About

İt is a peer to peer chat application . it’s developed on python with socket library

Источник

Saved searches

Use saved searches to filter your results more quickly

You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session.

Читайте также:  User agent device javascript

License

grakshith/p2p-chat-python

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?

Sign In Required

Please sign in to use Codespaces.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching GitHub Desktop

If nothing happens, download GitHub Desktop and try again.

Launching Xcode

If nothing happens, download Xcode and try again.

Launching Visual Studio Code

Your codespace will open once ready.

There was a problem preparing your codespace, please try again.

Latest commit

Git stats

Files

Failed to load latest commit information.

README.md

A simple to use chat program that uses sockets and multi-threading

This is a p2p chat program written in python. The traditional client server based chat is also supported

The clients can connect to the server through client.py

The p2p version can be started using the command

Alternatively, it can be run from the terminal itself. ####1. Make the files executable

$chmod u+x Server.py Client.py p2p.py

The client asks for the hostname and the port on which the server is listening. Then an attempt is made to connect to the server. If everything is all right, the client should prompt you to start typing your messages. Else an exception is thrown.

##2. Things to be implemented yet

##3. General Feel free to report bugs. Or shoot an e-mail to hehaichi@gmail.com

This work is licensed with the MIT license

####The MIT License (MIT) Copyright (c) 2015 Rakshith G

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the «Software»), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED «AS IS», WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Читайте также:  Поиск коэффициентов уравнения python

Источник

Writing a P2P chat application in Python

Is it possible to write a peer-to-peer chat application in Python? I am thinking of this from a hobbyist project point-of-view. Can two machines connect to each other directly without involving a server? I have always wondered this, but never actually seen it implemented anywhere so I am thinking there must be a catch somewhere. PS: I intend to learn Twisted, so if that is involved, it would be an added advantage!

3 Answers 3

Yes. You can do this pretty easily with Twisted. Just have one of the peers act like a server and the other one act like a client. In fact, the twisted tutorial will get you most of the way there.

The only problem you’re likely to run into is firewalls. Most people run their home machines behind SNAT routers, which make it tougher to connect directly to them from outside. You can get around it with port forwarding though.

Yes, each computer (as long as their on the same network) can establish a server instance with inbound and outbound POST/GET.

I think i am way too late in putting my two bits here, i accidentally stumbled upon here as i was also searching on similar lines. I think you can do this fairly easily using just sockets only, however as mentioned above one of the machines would have to act like a server, to whome the other will connect.

I am not familiar with twisted, but i did achieved this using just sockets. But yes even i am curious to know how would you achieve peer2peer chat communication if there are multiple clients connected to a server. Creating a chat room kind of app is easy but i am having hard time in thinking how to handle peer to peer connections.

Can you explain how you deal with users in different networks? using TCP in a local networks works well but if the end points are behind routers there is an issue finding the correct ports. As described above portforwarding solve the problem, but that force users to manually temper with the router configuration. Although this can be done automatically, I have not been able to do so using python.

Источник

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