Another interesting application of Nostr is to store the source code in a decentralized and uncensored way, developers can also discuss and propose improvements in the code through replays, in addition the code is already automatically signed by the key of who published it, bye bye Github!

Here is a P2P chat code example in Python:

-----(server.py)-----

import socket

#Initial IP and port configuration

print('Do you want to use ipv4 or ipv6?')

ipdecider = input()

print('Write your IP below:(can be localhost, internal ip, or external ip)')

hostinput = input()

HOST = hostinput

print('Write the port to be used below by this server (ex: 50000):')

portinput = input()

portinput = int(portinput)

PORT = portinput

if ipdecider == 'ipv4':

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

s.bind((HOST, PORT))

s.listen()

print('Show IP and Port so someone can communicate with you:', HOST, ':', PORT)

c, end = s.accept()

#After a client connects to the server, the program executes the code below (ipv4)

finished = False

print('Connection received! Chat started :)')

print('Type ttt to end the chat')

while not finished:

msg = c.recv(1024).decode('utf-8')

if msg == 'ttt':

finished = True

print('Received:', msg,'Send ttt back to close the circuit')

else:

print('Received:', msg)

c.send(input('Send: ').encode('utf-8'))

#End of connection (ipv4)

c.close()

s.close()

if ipdecider == 'ipv6':

s = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)

s.bind((HOST, PORT))

s.listen()

print('Show IP and Port so someone can communicate with you:', HOST, ':', PORT)

c, end = s.accept()

#After a client connects to the server, the program executes the code below (ipv6)

finished = False

print('Connection received! Chat started :)')

print('Type ttt to end the chat')

while not finished:

msg = c.recv(1024).decode('utf-8')

if msg == 'ttt':

finished = True

print('Received:', msg,'Send ttt back to close the circuit')

else:

print('Received:', msg)

c.send(input('Send: ').encode('utf-8'))

#End of connection (ipv6)

c.close()

s.close()

---------------------

-----(client.py)-----

import socket

#IP and Port of the server you are going to connect to

print('Do you want to use ipv4 or ipv6?')

ipdecider = input()

print('Write Server IP below:')

hostinput = input()

HOST = hostinput

print('Write Server Port below (ex: 50000):')

portinput = input()

portinput = int(portinput)

PORT = portinput

if ipdecider == 'ipv4':

c = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

c.connect((HOST, PORT))

#If the connection to the server works, run the code below (ipv4)

finished = False

print('Connection success! Chat started :)')

print('Type ttt to end the chat')

while not finished:

c.send(input('Send: ').encode('utf-8'))

msg = c.recv(1024).decode('utf-8')

if msg == 'ttt':

finished = True

print('Received:', msg,'Send ttt back to close the circuit')

else:

print('Received:', msg)

#End of connection (ipv4)

c.close()

if ipdecider == 'ipv6':

c = socket.socket(socket.AF_INET6, socket.SOCK_STREAM)

c.connect((HOST, PORT))

#If the connection to the server works, run the code below (ipv6)

finished = False

print('Connection success! Chat started :)')

print('Type ttt to end the chat')

while not finished:

c.send(input('Send: ').encode('utf-8'))

msg = c.recv(1024).decode('utf-8')

if msg == 'ttt':

finished = True

print('Received:', msg,'Send ttt back to close the circuit')

else:

print('Received:', msg)

#End of connection (ipv6)

c.close()

---------------------

Reply to this note

Please Login to reply.

Discussion

No replies yet.