ReadLine bug?
BlitzMax Forums/BlitzMax Programming/ReadLine bug?
| ||
Hi! Ok i Have some code and its currently not working. Here it is.Framework BRL.Socket Import BRL.SocketStream Import BRL.StandardIO Global serverIP = HostIp("83.149.87.203") Global port = 7778 Local socket:TSocket=CreateUDPSocket() ConnectSocket(socket,serverIP,port) Local stream:TStream=CreateSocketStream(socket,autoclose=False) WriteLine(stream,"\info\") Repeat Print ReadLine(stream) Until Eof(stream) CloseSocket(socket) It connects fine and sends the string fine. But the problem is I can't read the response from the server with BlitzMax. Every other prog I used gets the response. I think this is a bug in blitzmax because I'm checking my packets being recieved and the server does respond. Look here: 'http://img472.imageshack.us/my.php?image=whatthe0qh.png' I dont know the forum codes either. How do I make a link to this picture? the forum automatically includes it. And why does UDP always report its been connected when it the ip address is not valid. |
| ||
Dunno about the first one, but UDP never connects to anything. It just sends to a given IP. So maybe that's why it's reporting always connected. It's a connectionless protocol. |
| ||
oh ok. cool n thanks. now im just waiting for a response about this problem. is there a requests section in this forum? i wanna request for a timeout when connecting to an ip but i dont know where. :/ |
| ||
Like tonyg says Bump 'cos same at 1.18 :) |
| ||
bump 'cos it works in PureBasic |
| ||
Hi, Works fine if I change 'CreateUDPSocket' to 'CreateTCPSocket', serverIP to "www.blitzbasic.com" and serverPort to 80. With your ip/port the ConnectSocket is returning false - if: failing. If I try and 'connect' via firefox by typing... 83.149.87.203:7778 ...in the address bar, I get "The connection was refused when attempting to connect...blah", perhaps indicating a firewall issue? |
| ||
thanks for your response. im pretty sure the server runs with udp packets. its an unreal tournament server. so i can only send through a udp connection. :/ with TCP it wont respond. I changed to this Framework BRL.Socket Import BRL.SocketStream Import BRL.StandardIO Global serverIP = HostIp("83.149.87.203") Global port = 7778 Local socket=CreateUDPSocket() Local connect=ConnectSocket(socket,serverIP,port) Local stream=CreateSocketStream(socket,autoclose=False) Select socket Case 0 Print "Couldn't create UDP socket" Case 1 Print "UDP socket created" Default Print "Unknown error!" EndSelect Select connect Case 0 Print "Couldn't connect to server" Case 1 Print "Connected to server" Default Print "Unknown error!" EndSelect Rem WriteLine(stream,"\info\") Repeat Print ReadLine(stream) Until Eof(stream) CloseSocket(socket) EndRem It prints UDP socket created Connected to server It does connect. And the data is being sent and recieved. Look! 'http://img472.imageshack.us/my.php?image=whatthe0qh.png' The left top window shows the response from the server. Ie packet no. 3 and the top right one is the message sent. Packet no.1 I did this in PureBasic and it works. So it cant be firewall issues. Ill even try it without the firewall and see. Im pretty sure theres an error where a buffer or something in the modules arent reading the response. |
| ||
Hi, UDP sockets are 'stateless' and are unlikely to work properly (or for long anyway) with socketstreams. You'll probably need to do 'raw' read/writes and perhaps your own ReadLine routine. Anyway, moving this to programming... |
| ||
How can we get the IP and Port of the sender of UDP messages like BlitzPlus could do fine? SocketRemoteIP just seems to work for me with TCPSockets which have undergone a connection. Any explanations and code would be a great help - if it works. |
| ||
The only way I found to do this is:Local bytesbefore:Int = socket.ReadAvail() Local buffer:TBank = CreateBank(bytesbefore) Local from_ip:Int,from_port:Int recvfrom_(socket._socket,buffer.Buf(),bytesbefore,0,from_ip,from_port) 'Function recvfrom_( socket,buf:Byte Ptr,size,flags,sender_ip Var,sender_port Var) Local bytesafter:Int = socket.ReadAvail() Local bytesread:Int = bytesbefore-bytesafter buffer.Resize(szread) Local data:TBankStream = CreateBankStream(buffer) After this from_ip contains the sender's IP an from_port contains the sender's port. You can read your recived data from the BankStream data. Ps: I hope the Code is ok, id didn't test it. |