当前位置: 技术问答>linux和unix
VC与linux下socket通讯
来源: 互联网 发布时间:2017-04-01
本文导语: VC下的server端程序和linux下的client端程序, 不知道为什么通讯不了,知道的说下,谢谢,代码如下: server端pc下VC编译 #include #include #pragma comment (lib,"WS2_32.lib") #define USERPORT 10001 #define HOST_IP_ADDR "127.0.0.1" main(int...
VC下的server端程序和linux下的client端程序, 不知道为什么通讯不了,知道的说下,谢谢,代码如下:
server端pc下VC编译
#include
#include
#pragma comment (lib,"WS2_32.lib")
#define USERPORT 10001
#define HOST_IP_ADDR "127.0.0.1"
main(int argc,char *argv[])
{
printf("begin at main n");
char buf[128];
SOCKET s,ns;
struct sockaddr_in client;
struct sockaddr_in server;
int namelen,pklen;
int status;
WSADATA wsd;
if((status=WSAStartup(MAKEWORD(2,2),&wsd))!=0)
{
perror("wsastartup() failed:");
exit(1);
}
printf("WSAStartup end n");
//if((s=socket(AF_INET,SOCK_STREAM,0))
server端pc下VC编译
#include
#include
#pragma comment (lib,"WS2_32.lib")
#define USERPORT 10001
#define HOST_IP_ADDR "127.0.0.1"
main(int argc,char *argv[])
{
printf("begin at main n");
char buf[128];
SOCKET s,ns;
struct sockaddr_in client;
struct sockaddr_in server;
int namelen,pklen;
int status;
WSADATA wsd;
if((status=WSAStartup(MAKEWORD(2,2),&wsd))!=0)
{
perror("wsastartup() failed:");
exit(1);
}
printf("WSAStartup end n");
//if((s=socket(AF_INET,SOCK_STREAM,0))