Wont go after 1st if

Hi, I set up the program to get a user name and password but it seems not want to go after or even start the 1st if for my program. The 1st while loops it befor it gets to the password half and i’m not sure why, can anyone help? Thanks if you can.

# Server program

from socket import *
import time


# Set the socket parameters
host = "--------"
port = ---------
buf = 1024
addr = (host,port)

# Create socket and bind to address
UDPSock = socket(AF_INET,SOCK_DGRAM)
UDPSock.bind(addr)


# Receive messages
while 1:
        data,addr = UDPSock.recvfrom(buf)
        print data
        if not data:
		print "Client has exited!"
		break

        else:
		data2 = data + ".txt"
		print data
		print data2
		f = open(data2,"r")
		lineList = f.readlines()
		f.close()
		name = "Name: " + data
		print name
		if name == lineList[0]:
				  print Data
				  data,addr = UDPSock.recvfrom(buf)
				  print data
				  password = "Password: " + data
				  print password
				  if Password == lineList[1]:
						        print "Ok..."
						        while 1:
								data,addr = UDPSock.recvfrom(buf)
								print data
								if not data:
									print "Client has exited!"
									break
								else:
									print "\nReceived message '", data,"'"
				  else:
						print "Nope..."
						break
# Close socket
UDPSock.close()

If I’m not mistaken, readlines() leaves “\n” at the end of the line. Strip it out.

Apart from the problem you have, i’d highly recommend you to use TCP not UDP for networked authentication…

Using UDP your client might send the login-data, but the server might never receive it. The client will never know that the data was lost during transmission.

TCP in contrast, checks if data is received and resends it until it’s received correctly. This is also the reason many games use UDP, if you lose a unimportant package, it might not be severe, but making the transmission slower often is fatal to the gameplay.

Using TCP you can also check if both clients are still online (from server and client side), while with UDP the client or server might be gone since a long time until you realize that.

just my 2 cents

Thanks that seem to work.

True, I was going to work on that nexts and have a time out. If time > 10s then resend data - just incase the data was never sent or goten.

TCP seems to be good with authentication, but way slow when it comes down to game play; on the other hand UDP seems to be fast, but comes with dead lines (mean if data doesnt show up it will never know). I was going to work around on that tho and send data packs with numbers. Like server sends out 3 things, client only gets 2, client side looks at what it got like (file 1-1-3) (file 1-3-3) , it reads the file headings and sees it missing 1-2-3 so it ask for file 1-2-3 again.

Lol, not 100% sure if this will work or is a dum idea. I just thought it would be faster this way.

it can grossly work.

You just have to remember to keep track of the figures from both side
on client and on server.

when you send a message from Ci to S, your message could have in the header those 2 informations:Rci,Sci (last message received by client i, last message sent by client i)
and server keep it’s own version of this information.

This work well for lost message but not for out of order message.
In this case you may have to aknowledge (ACK or NACK) specific message number by piggybacking their ID on message sent back (ex from server to Client, you acknowledge reception of message from client to server)

Even with this you still have the issue that at any time, your set of message availabe on the server or on the client is not warranted to be complete and ordered.
So if you need causality then you need to poll the set in a specific way.

Basically you make an UDP Protocol with possibility to send order and / or reliable packet.
This would be RUDP (but linux only)
Or Enet (C only, small and efficient,used in sauerbraten engine) or Raknet (CPP / partial incomplete binding for python, feature rich and mostly efficient ).

For most game, TCP could be a valuable first choice (if not FPS game).

lol, ok x.x; I guess I have to rewrite my code for TCP now o.o;