首页 Soft PlugIn RAN乱 Dev开发 Info资料 English WAP 留言 登陆 注册
-
Posted by Yippee | 评论(0) | 引用(0) | 阅读692次
20080307 linux c socket soap

20080307 windows c socket soap
http://www.shengfang.org

arm-elf-gcc  -nostartfiles -Wl, -elf2flt  -o sockaspx  socketaspx.c   -I/home/sf/sfsf/uClinux-IST/uClibc/include -L/home/sf/sfsf/uClinux-IST/uClibc/lib -fpermissive  /home/sf/sfsf/uClinux-IST/lib/uClibc/lib/crt0.o  -lc -lpthread -lm

#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <netdb.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <sys/socket.h>
#define PORT 5566 /* the port client will be connecting to */
#define MAXDATASIZE 1500 /* max number of bytes we can get at once */
int main(int argc, char *argv[])
{
int sockfd, numbytes;
char buf[MAXDATASIZE] ;
char*   req="POST /test/websrvtest/s.asmx HTTP/1.1\r\n" 
  "Host: www.shengfang.org:5566\r\n
  "User-Agent: gSOAP/2.7\r\n" 
  "Content-Type: text/xml; charset=utf-8\r\n" 
  "Content-Length: 481\r\n"
  "Connection: close\r\n" 
  "SOAPAction: \"http://tempuri.org/HelloWorld\"\r\n\r\n"

  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:SOAP-ENC=\"http://schemas.xmlsoap.org/soap/encoding/\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:ns2=\"http://tempuri.org/Service1Soap\" xmlns:ns1=\"http://tempuri.org/\" xmlns:ns3=\"http://tempuri.org/Service1Soap12\"><SOAP-ENV:Body><ns1:HelloWorld></ns1:HelloWorld></SOAP-ENV:Body></SOAP-ENV:Envelope>";
 
struct hostent *he;
struct sockaddr_in their_addr; /* connector's address information */
if(argc != 2)
{
   fprintf(stderr,"usage: client hostname\n");
   exit(1);
}
printf("1\r\n");
if((he=gethostbyname(argv[1])) == NULL)
{
   /* get the host info */
   herror("get host by name" ) ;
         exit(1);
}
printf("2\r\n");
if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1)
{
   perror("socket");
   exit(1) ;
}
printf("3\r\n");
their_addr.sin_family = AF_INET; /* host byte order */
their_addr.sin_port = htons(PORT); /* short, network byte order */
their_addr.sin_addr = *((struct in_addr *)he->h_addr);
bzero(&(their_addr.sin_zero), 8); /* zero the rest of the struct */
printf("4\r\n");
if (connect(sockfd, (struct sockaddr *)&their_addr, sizeof(struct sockaddr)) == -1)
{
   perror("connect") ;
   exit( 1 ) ;
}
printf("5\r\n");
   if (send(sockfd,req, strlen(req), 0) == -1)
 {
     perror("send error");
    close(sockfd);
    exit(0);
   }
   printf("6\r\n");
numbytes=1;
while(numbytes>0) 
 {  
  numbytes=recv(sockfd,buf,MAXDATASIZE,0); 
  if(numbytes>0) 
   buf[numbytes]=0; 
  else 
   buf[0]=0; 
  printf("\nReceived   bytes:%d\n",numbytes); 
  printf("Result:\n%s",buf); 
  } 

printf("7\r\n");
buf[numbytes] = '\0';
printf("Received: %s",buf);
close(sockfd);
printf("8\r\n");
return 0;
}


字体:

Permanant URI永久地址 http://www.shengfang.org/blog/p/20080307linuxcsocketsoap.php
Trackback URI引用地址 http://www.shengfang.org/blog/tb.php?tb_id=1228568713

2008年12月6日21:05星期六  [Dev开发] 追踪此文的RSS
提示:
此文还没有评论。

称呼:    登陆   注册
   不注册,但记住我的信息
邮件:
(非必须)
评论: [UBB代码帮助]
粗体 斜体 下划线 链接 水平线 引用



验证码: 请输入你看见的数字
关闭UBB      提交时自动将内容复制到剪贴板

公告
Fire and Motion!

统计信息
[Yippee]||[统计]||日志:1967
在线: 18||用户: 2593 [列表]
今日:1189||到访:3118360
Rss:||评论:1631

最新日志

最新评论

友情链接

日历
2008 - 11
      1
2345678
9101112131415
16171819202122
23242526272829
30      

最新引用

搜索

归档

杂项
Get RSS Feed (Version 2.0)
Get Atom Feed (Version 0.3)
编码:  UTF-8