Socket streaming
BlitzMax Forums/BlitzMax Programming/Socket streaming
| ||
Hi all, have been playing with Sockets and writing / reading from a stream. It's been quiet succesful, i have written a small app that can log onto my smtp server and send a mail and also then onto my pop3 server and check for new mail. My questions is simple, has anyone ever managed to succesfully log onto the msn server and log into an account? looking at docs on the net i can find what should happen, and i can find the server and connect but thats about it, i cant send the xfer request or login details? kinda off topic i guess but hey, i'm using blitz to do it :-S |
| ||
ok, getting further on this, however with some of the commands i issue to the server (using Writeline(stream:TStream,string); ) i need to add a carriage return and line feed at the end, how can i do this? i presume i need to either some kinda ascii conversion of byte code etc.. (making this up as i go :-) ) n e suggestions would be swell :) |
| ||
Yeah you got to find the ascii value for the return and then use like Chr$(return) or whatever it is in blitzmax, to add that character on the end. |
| ||
figured it was char(13) + chr(10) although msn server just accepts \r\n at end of string now connects to correct servers and authenticates, which is awsome, just need to extract ip address from a string |
| ||
grrrr...ok extract ip address to a string is simple. now when i pass the string to connectsocket as remoteip parament it says it cannot cover to int, so then i try adding .toint() but it only gives first 3 digits of ip |
| ||
Call HostIP( "your-string-ip-here" ) and use that return value as the IP to pass to connectsocket. |
| ||
Just for your info, the reason you were only getting hte first 3 digits of the IP by calling .toint() is because it was trying to extract an integer from a string that looks like "127.127.127.127" and as soon as it hit the period, it stopped and returned the first "127". Just a heads up to help ya since knowing stuff like that can help in the debugging process. |
| ||
Hi all. running into a problem. after i have obtained an ip i cannot connect to it. dunno if its summin i am doing with this code, just wondered if n e one else could try this code, just replace my@... with your msn username: Global socket:TSocket = CreateTCPSocket(); Global stream:Tsocketstream; Global ipaddress:String; If ConnectSocket (socket,HostIp("messenger.hotmail.com"),1863) Then Print "Socket Connected" stream = CreateSocketStream(socket); If (stream) Then Print "stream created"; WriteLine (stream,"VER 1 MSNP9 CVR0\r\n"); Print ReadLine(stream); WriteLine(stream,"CVR 2 0x0409 win 5.10 i386 MSNMSGR 7.0.0816 MSMSGS my@..."); Print ReadLine(stream); WriteLine (stream,"USR 3 TWN I my@..."); xx:String = ReadLine(stream); Print xx; End If count:Int=0; collect:Int=0; Repeat count=count+1; If Mid(xx,count,1)=2 Then collect = 1; If collect = 1 Then 'If Mid(xx,count,1)<> "." Then ipaddress=ipaddress+Mid(xx,count,1); 'EndIf EndIf Until Mid(xx,count+1,1)=":" CloseStream(stream); CloseSocket(socket); Print ("Connecting to " + ipaddress); If ConnectSocket (socket,HostIp(ipaddress),1863) Print("Connected"); WriteLine (stream,"VER 1 MSNP8 CVR0\r\n"); Print ReadLine(stream); Else Print("Unable to connect"); EndIf EndIf CloseStream(stream); CloseSocket(socket); i know code is kinda sloppy but this was only intended as a test, only thing i can think may cause an issue reading the docs is that once its obtained the ip a msn client would connect to the host name of the ip, but cant see how thats different than connecting to the ip *EDIT - seems i need a way to convert a dotted ip string to an int. value for the createsocket() function |
| ||
Socket connects, streams created , ends up with: Connecting to 207.46.107.46 Unable to connect Process complete |
| ||
thankin u, sames as i get, which is kinda strange really |
| ||
ok, got this further now, i can redirect the server by using two sockets /streams, it seems they have to run side by side for the redirect to work, only thing i need now is to do the authentification parth which is done via https as per this n e idea how i can do this? here is updated code (again a bit sloppy): SuperStrict Global socket:TSocket[3]; Global stream:Tsocketstream[3]; Global ipaddress:String; socket[0]=CreateTCPSocket(); socket[1]=CreateTCPSocket(); socket[2]=CreateTCPSocket(); Global xx:String; If ConnectSocket (socket[0],HostIp("messenger.hotmail.com"),1863) Then Print "Socket Connected" stream[0] = CreateSocketStream(socket[0]); If (stream[0]) Then Print "stream created"; WriteLine (stream[0],"VER 1 MSNP8 CVR0\r\n"); Print ReadLine(stream[0]); WriteLine(stream[0],"CVR 2 0x0409 win 5.10 i386 MSNMSGR 7.0.0816 MSMSGS me@..."); Print ReadLine(stream[0]); WriteLine (stream[0],"USR 3 TWN I me@..."); xx = ReadLine(stream[0]); Print xx; End If Local count:Int=0; Local collect:Int=0; Repeat count=count+1; If Mid(xx,count,1)=2 Then collect = 1; If collect = 1 Then 'If Mid(xx,count,1)<> "." Then ipaddress=ipaddress+Mid(xx,count,1); 'EndIf EndIf Until Mid(xx,count+1,1)=":" Print ("Connecting to " + ipaddress); If ConnectSocket (socket[1],HostIp(ipaddress),1863) Print("Connected"); stream[1] = CreateSocketStream(socket[1]); WriteLine (stream[1],"VER 4 MSNP8 CVR0\r\n"); Print ReadLine(stream[1]); WriteLine (stream[1],"CVR 5 0x0409 win 4.10 i386 MSNMSGR 5.0.0544 MSMSGS me@..."); Print ReadLine(stream[1]); WriteLine (stream[1],"USR 6 TWN I me@..."); Print ReadLine(stream[1]); Else Print("Unable to connect"); EndIf EndIf CloseStream(stream[0]); CloseSocket(socket[0]); CloseStream(stream[1]); CloseSocket(socket[1]); |