Getting data from a server, login fails
Posted: Mon Aug 04, 2014 1:19 pm
For some time now I've been trying to setup a connection to a certain server. In C#, this works, but I cannot get it to work in Purebasic.
I've tried several ways of sending the data, but I think it might fail on the 0 character in the string. Is there anyway to get this working?
Code: Select all
TcpClient client = new TcpClient();
client.Connect("servername",port);
char chr0 = (char)0;
char chr1 = (char)1;
string input = String.Format("{0}username{1}password{2}", chr1, chr0, chr0);
// Stream string to server
NetworkStream s = client.GetStream();
ASCIIEncoding asen = new ASCIIEncoding();
byte[] ba = asen.GetBytes(input);
s.Write(ba, 0, ba.Length);
// Read response from server.
byte[] buffer = new byte[1024];
Code: Select all
logondata=chr(1)+username+chr(0)+password+chr(0)
If Initnetwork()
ConnectionID=OpenNetworkConnection(address,port)
if ConnectionID
Debug SendNetworktring(ConnectionID,logondata,len(logondata)
Repeat
Select NetworkClientEvent(connectionID)
Case #PB_NetworkEvent_Disconnect
Debug "disconnected":End
Case #PB_NetworkEvent_Data
Debug ReceiveNetworkData(ConnectionID,*buffer,1024)
Debug PeekS(*buffer)
Case #PB_NetworkEvent_None
Debug "no data"
EndSelect
Delay(100)
Until Quit=1
EndIf
EndIf