mIRC Homepage

Socket error

Posted By: DeSync

Socket error - 01/12/10 09:24 PM

Hi, there

Code:
alias sockstart { 
  echo -s * Starting socket sockopen open_socket 127.0.0.1 80 
} 
on *:SOCKOPEN:open_socket: { 
  if $sockerr > 0 { 
    echo -s * Can't connect to socket. 
  } 
  else { 
    sockwrite -nt $sockname GET /socket/index.php HTTP/1.1
    sockwrite -nt $sockname Connection: Keep-Alive 
    sockwrite -nt $sockname Host: 127.0.0.1 
    sockwrite -nt $sockname $str($crlf,2) 
  } 
} 
on *:SOCKREAD:open_socket: { 
  if $sockerr > 0 { 
    echo -s * Error 
  } 
  else { 
    var %read 
    if !$sock($sockname).mark { 
      sockread %read if %read == $null { 
        sockmark $sockname 1 
      } 
    } 
    else { 
      sockread %read 
    } 
    echo -s * %read 
  } 
}


Can anyone find something bad in this script? It makes me crazy. It returns header successfully, but data can't.

/socket/index.php contains code:

Code:
<?PHP 

echo 'data'; 

?>


Regards
Posted By: Riamus2

Re: Socket error - 01/12/10 10:19 PM

Try using HTTP/1.0 instead of HTTP/1.1 and see if that helps.
Posted By: DeSync

Re: Socket error - 02/12/10 05:00 PM

Hi, I've got this:

Code:
HTTP/1.1 200 OK
Date: Thu, 02 Dec 2010 16:58:09 GMT
Server: Apache/2.2.11 (Win32) PHP/5.3.0
X-Powered-By: PHP/5.3.0
Content-Length: 7
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html


Content length is ok.

I'm using 7.15 version
Posted By: argv0

Re: Socket error - 02/12/10 05:13 PM

You completely ignored Riamus' advice and are still using HTTP/1.1
Posted By: DeSync

Re: Socket error - 02/12/10 05:14 PM

I'm using 1.0 but it returns 1.1.

Don't know why.
Posted By: FroggieDaFrog

Re: Socket error - 02/12/10 06:36 PM

Try something like this, just to see where you get:
Code:
alias sockopen {
  echo 12 -s * Trying to open connection with 127.0.0.1:80
  sockopen open_socket 127.0.0.1 80
}
on *:SOCKOPEN:open_socket:{
  if ($sockerr) { 
    echo 04 -s * Unable to connect: $sock($sockname).wsmsg 
  }
  else {
    echo 12 -s * Connection established.
    sockwrite -n $sockname GET /socket/index.php HTTP/1.0
    sockwrite -n $sockname Connection: Keep-Alive
    sockwrite -n $sockname
  }
}
on *:SOCKWRITE:open_socket:{
  if ($sockerr) { 
    echo 04 -s * Unable to send data through socket: $sock($sockname).wsmsg 
  }
  else {
    echo 12 -s * Send data to socket.
  }
}
on *:SOCKREAD:open_socket:{
  if ($sockerr) {
    echo 04 -s * Unable to read data from socket: $sock($sockname).wsmsg 
  }
  else {
    var %tmp
    echo 12 -s * Reading data from socket
    :loop
    sockread %tmp
    if (!$sockbr) { return }
    echo -s * %tmp
    goto loop
  }
}
on *:SOCKCLOSE:open_socket:{
  if ($sockerr) { 
    echo 04 -s * Socket closed unexpectedly: $sock($sockname).wsmsg 
  }
  else { 
    echo 12 -s * Socket closed by server. 
  }
}


Edited to add some more echos, and fix a few errors
Posted By: jaytea

Re: Socket error - 02/12/10 06:40 PM

has no one noticed this line in the original code:

Code:
sockread %read if %read == $null { 


:P
Posted By: DeSync

Re: Socket error - 02/12/10 06:42 PM

Yeah, I saw that.

It's ok in mirc, just error in text, while copying.
Posted By: FroggieDaFrog

Re: Socket error - 02/12/10 06:43 PM

How about the /sockopen being on the same line as the /echo claiming the socket is being opened?
Posted By: DeSync

Re: Socket error - 02/12/10 06:48 PM

Well,

All of that is copy error. Couse I've posted it on some other web and copyed to this.
So it should echo sockopen instead opening socket.

But it open socket, so it's OK.
Posted By: DeSync

Re: Socket error - 02/12/10 11:00 PM

And why sometimes responds

Connection: close

instead of

Connection: Keep-Alive

Posted By: DeSync

Re: Socket error - 03/12/10 04:47 PM

So, there's no any errors in script?

Just mIRC won't reply correctly?
Posted By: DeSync

Re: Socket error - 04/12/10 05:15 PM

blush

I've realized that there's problem with server side.
But I can't get it why. What does server side must contain?

<html> , <head> , <body> , <meta> ?

When I try some other web I get source code of it.
My current server side script is in first post above.

Regards
Posted By: m0viefreak

Re: Socket error - 07/12/10 11:46 AM

The server might require more headers such as
User-Agent,Accept-Encoding, ...

Posted By: DeSync

Re: Socket error - 07/12/10 12:03 PM

Code:
sockwrite -n $sockname GET /socket/index.php HTTP/1.0
sockwrite -n $sockname Connection: Keep-Alive
sockwrite -n $sockname User-Agent: $+(mIRC/, $version) (Windows NT; en)
sockwrite -n $sockname Accept: */*
sockwrite -n $sockname Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
sockwrite -n $sockname Keep-Alive: 300
sockwrite -n $sockname Accept-Language: en-us,en;q=0.5
sockwrite -n $sockname Accept-Encoding: gzip,deflate
sockwrite -n $sockname Host: 127.0.0.1 
sockwrite -n $sockname $str($crlf, 2)


This is my current header.
Posted By: DeSync

Re: Socket error - 07/12/10 12:12 PM

And when I use this script for google.com 80 I got this:

Code:
HTTP/1.0 301 Moved Permanently
Location: http://www.google.com/
Content-Type: text/html; charset=UTF-8
Date: Tue, 07 Dec 2010 12:10:34 GMT
Expires: Thu, 06 Jan 2011 12:10:34 GMT
Cache-Control: public, max-age=2592000
Server: gws
Content-Length: 219
X-XSS-Protection: 1; mode=block
Connection: Keep-Alive

<HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8">
<TITLE>301 Moved</TITLE></HEAD><BODY>
<H1>301 Moved</H1>
The document has moved
<A HREF="http://www.google.com/">here</A>.
</BODY></HTML>


And it's good.
Posted By: Tomao

Re: Socket error - 07/12/10 06:03 PM

It's not good. You get this:
Quote:
HTTP/1.0 301 Moved Permanently
The 301 error means that the info you've requested has been moved. The http server will send you the new location in the Location field of the headers. You're supposed to get something like:
Quote:
HTTP/1.0 200 OK
to indicate the info has been successfully requested.
Posted By: DeSync

Re: Socket error - 07/12/10 07:57 PM

Nevermind, I've tried other pages with 200 OK, and same. Get data, but in my case can't. We are talking here about no replying data. Just header. In this case it returns data whatever it is.
Posted By: DeSync

Re: Socket error - 12/12/10 03:15 PM

Is it against of rules of board to BUMP?
Posted By: Tomao

Re: Socket error - 12/12/10 03:49 PM

It's your server-side to blame. You can't possibly get help from people who are clueless as to what setup you have of your source or the data you try to get the info from.
Posted By: DeSync

Re: Socket error - 12/12/10 06:02 PM

Well, in first post u have data on server side.
I've tried it on local and on remote. It's same.

Also I've tried to parent folder where is forum installed and I got source of forum. Which is fine.

When I add /folder/file.php it can't return.
© 2022 mIRC Discussion Forums