标题:求ASP socket例子
只看楼主
huaxialonger
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2009-3-18
结帖率:100%
 问题点数:0 回复次数:4 
求ASP socket例子
今天从网上找了一天,关于ASP Socket的例子,都没有找到。希望大家能给个例子,实现从服务器上获取信息就可以。
下面是PHP的源码,求相关的ASP源码
function getBalance($reg, $pwd){
        $res = new ResFee();
        if($reg == null || strlen($reg) == 0){
            $res->result = -1;
            $res->des = "注册号不能为空!";
            return res;
        }
        if($pwd == null || strlen($pwd) == 0) {
            $res->result = -1;
            $res->des = "密码不能为空!";
            return res;
        }
        $path = "<END><COMMAND>S059</COMMAND><REGISTRYCODE>$reg</REGISTRYCODE><PWD>$pwd</PWD></END>";
        
        
        $path=mb_convert_encoding($path, "UTF-8", "GBK");      

            $address = gethostbyname($this->host);
            /* Create a TCP/IP socket. */
            $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);   //主要是这个方法,在ASP里不知道怎么用
            $result = socket_connect($socket, $address, $this->port); //还有这个

            // make header
            $in = "GET ".$path." HTTP/1.0\r\n";
            $in .= "Content-Type: application/x-www-form-urlencoded\r\n";
            $in .= "\r\n\r\n";
            // out data
            $out = '';
            
            socket_write($socket, $in, strlen($in));          //不知道这个方法在ASP里有没有对应的方法
            while ($out = socket_read($socket, 2048)) {        
                $temp_out .= $out;
                //结束标志
                if (preg_match("/<\/DES>/",$temp_out )) {
                    break;
                }
            }
            //关闭socket链接
            socket_close($socket);

            //处理返回结果
            preg_match("/<DES>(.*)<\/DES>/i",$temp_out,$matches);
            
            //处理返回结果$matches[1]
            $i = strpos($matches[1],'result=', 0);
            $j = strpos($matches[1],'&balance=', 0);
            if($j >0){
                if(($j - $i - 7) <= 0){
                    $res->result = -1;
                    $res->des = '接收服务器错误!';
                    $res->balance = -1;
                }else if (($j - $i - 7) > 0) {
                    $result = (int)substr($matches[1],$i+7,$j);
                    if((strlen($matches[1])- $j - 4)>0){
                        $des = substr($matches[1],$j + 9,strlen($matches[1]));
                        $res->result = $result;
                        $res->des = '查询余额成功';
                        $res->balance = (int)$des;
                    }else{
                        $res->result = -1;
                        $res->des = '接收服务器错误!';
                        $res->balance = -1;
                    }
                }
            }
            return $res;        
    }
搜索更多相关主题的帖子: socket ASP 例子 
2010-07-19 17:06
huaxialonger
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2009-3-18
得分:0 
手头只有一PHP例子,但需要ASP。。。,谁帮忙给翻译一下
function getBalance($reg, $pwd){
        $res = new ResFee();
        if($reg == null || strlen($reg) == 0){
            $res->result = -1;
            $res->des = "注册号不能为空!";
            return res;
        }
        if($pwd == null || strlen($pwd) == 0) {
            $res->result = -1;
            $res->des = "密码不能为空!";
            return res;
        }
        $path = "<END><COMMAND>S059</COMMAND><REGISTRYCODE>$reg</REGISTRYCODE><PWD>$pwd</PWD></END>";
        
        
        $path=mb_convert_encoding($path, "UTF-8", "GBK");      

            $address = gethostbyname($this->host);
            /* Create a TCP/IP socket. */
            $socket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
            $result = socket_connect($socket, $address, $this->port);

            // make header
            $in = "GET ".$path." HTTP/1.0\r\n";
            $in .= "Content-Type: application/x-www-form-urlencoded\r\n";
            $in .= "\r\n\r\n";
            // out data
            $out = '';
            
            socket_write($socket, $in, strlen($in));
            while ($out = socket_read($socket, 2048)) {        
                $temp_out .= $out;
                //结束标志
                if (preg_match("/<\/DES>/",$temp_out )) {
                    break;
                }
            }
            //关闭socket链接
            socket_close($socket);

            //处理返回结果
            preg_match("/<DES>(.*)<\/DES>/i",$temp_out,$matches);
            
            //处理返回结果$matches[1]
            $i = strpos($matches[1],'result=', 0);
            $j = strpos($matches[1],'&balance=', 0);
            if($j >0){
                if(($j - $i - 7) <= 0){
                    $res->result = -1;
                    $res->des = '接收服务器错误!';
                    $res->balance = -1;
                }else if (($j - $i - 7) > 0) {
                    $result = (int)substr($matches[1],$i+7,$j);
                    if((strlen($matches[1])- $j - 4)>0){
                        $des = substr($matches[1],$j + 9,strlen($matches[1]));
                        $res->result = $result;
                        $res->des = '查询余额成功';
                        $res->balance = (int)$des;
                    }else{
                        $res->result = -1;
                        $res->des = '接收服务器错误!';
                        $res->balance = -1;
                    }
                }
            }
            return $res;        
    }
2010-07-19 18:03
yms123
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:版主
威 望:209
帖 子:12488
专家分:19042
注 册:2004-7-17
得分:0 
如果是远程调用的话可以用Web Service或Ajax方式个人觉得比socket要好得多,一般socket用在B/S系统多。
2010-07-20 13:12
huaxialonger
Rank: 1
等 级:新手上路
帖 子:11
专家分:0
注 册:2009-3-18
得分:0 
不是远程调用,只是从服务器上读取信息而已,需要一定的格式
S000101100-SJB-HUAX-015555Kssdhttp://www.
2010-07-21 09:45



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-313427-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.127528 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved