I'm not sure what the problem is, but I do not think it is a problem with MikeNet. I ran the following test code which worked fine:
Client:
` Declare variables
NET_LOG as byte
LOGIN1 as byte
uName$ as string
uPass$ as string
type tyPlayer
Key as double integer
endtype
` Create key
me = 0
dim Players(1) as tyPlayer
Players(me).Key = mn create key 128(125152,125515)
NET_LOG = 124
LOGIN1 = 254
uName$ = "Michael"
uPass$ = "My password"
` Create send packet
Send = mn create packet()
mn set memory size Send, 1024
mn Add Byte Send, NET_LOG
mn Add Byte Send, LOGIN1
mn Add String Send, uName$, len(uName$), 1
mn Add String Send, uPass$, 0, 1
print "Packet ready."
print "Key - "+str$(Players(me).key):sync
mn Encrypt Send, Players(me).key
print "Packet encrypted.":sync
` Start MikeNet and connect to server
mn start 1,0
result = mn connect(0,"127.0.0.1",5555,"127.0.0.1",5555,5,1)
if result = 0
print "Timed out..."
wait key
end
endif
if result = 1
print "Connected!"
endif
if result = -1
print "Error occurred whilst connecting"
wait key
end
endif
` Send packet
result = mn Send TCP (0, Send, 0, 0, 1)
if result = 0
print "Packet sent successfully"
print "It contained (decrypted):"
print "NET_LOG: " + str$(NET_LOG)
print "LOGIN1: " + str$(LOGIN1)
print "uName$: " + uName$
print "uPass$: " + uPass$
endif
if result = -1
print "Error occurred whilst sending"
wait key
end
endif
` End
print "All done!"
mn finish -1
wait key
end
Server:
` Start MikeNet and host server
mn start 1,0
RecvPacket as double integer
RecvPacket = mn create packet()
mn set memory size RecvPacket, 1024
DecryptKey = mn create key 128(125152,125515)
mn set local 0, "127.0.0.1", 5555, "127.0.0.1", 5555
result = mn start server(0,1,1,1)
if result = 0
print "Server started!"
endif
if result = -1
print "Server failed to start!"
endif
` Wait for packet to arrive
do
` Manage connections
Joined = mn client joined(0)
if Joined > 0
print "New client joined: "+str$(Joined)
endif
Left = mn client left(0)
if Left > 0
print "Client left: "+str$(Left)
endif
TcpPackets = mn Recv TCP(0,RecvPacket,1)
` When a packet is received, display data
if TcpPackets > 0
mn decrypt RecvPacket, DecryptKey
print "A packet has been received!"
print "It contains (decrypted): "
byReturn as byte
byReturn = mn Get Byte(RecvPacket)
print "NET_LOG: " + str$(byReturn)
byReturn as byte
byReturn = mn Get Byte(RecvPacket)
print "LOGIN1: " + str$(byReturn)
print "uName$: " + mn Get String(RecvPacket,0,1)
print "uPass$: " + mn Get String(RecvPacket,0,1)
endif
loop
mn Finish -1
Also regarding the code snippet you posted, there are some things that you may find useful to know (if you don't already):
1. The two lines below do the same thing. If the length parameter of mnAddString is 0, MikeNet will work out the length for you:
mn Add String Send, uName$, len(uName$), 1
mn Add String Send, uName$, 0, 1
2. When using mnGetByte, you must first store it in a variable before passing it to a function as I have done in the test code; this is a problem with DBP. [edit] This is actually an issue with MikeNet that will be fixed for the next version.
3. The variable in the below line does not hold a representation of the key (i.e it is completely unrelated to the key parameters). It now contains a memory address to the location of the key data.
Players(me).Key = mn create key 128(125152,125515)
Please let me know how you get on regarding this problem. Hope I helped