I am working on a client/server to make a simple chat. Client is in VB and server in python.
I would like to make my server stock my message, and i though the smartest was to build a linked list (I am a novice in python but much more advanced in C#).
What i try to store is composed of :
- the recipient (it is called dest here)
- the message (called msg)
I dont know how many, and i will overwrite if I have a new message for someone who already have a message stored
I tried that as class
class tabmessage:
def __init__(self, dest=None,msg=None, next=None):
self.dest = dest
self.msg = msg
self.next = None
and that as call
#I create the top of the chain on the beginning
messages = tabmessage(dest='Control',msg='Message Integrity')
... Then in a function later
#Setting the top of the chain
(d,m,s) = (messages.dest,messages.msg,messages.next)
#Looking for a similar dest in chain and getting at the end at the same time
while True:
if (d == tempdest):
m = (tempmsg+".")[:-1]
print("Overwrite of msg for" + d + " : " + m);
return
if (s is None):
break
(d,m,s)=(s.dest,s.msg,s.next)
#If I did not found it i try to add it to the chain
s = tabmessage(dest=(tempdest+".")[:-1],msg=(tempmsg+".")[:-1])
print("Trying to add : " + s.dest + " : " + s. msg)
The last print looks ok :
Trying to add : User : This is my message
but if i do :
print("Trying to add : " + messages.next.dest + " : " + messages.next. msg)
An error occured (NoneType don't have a dest element ...), so the top is still alone.
Or maybe if there is smarter way to do it in python ?