C语言socket连接问题!
[code]#include<windows.h>#include<stdio.h>#include<Winsock2.h>#pragmacomment(lib,"ws2...
[code]#include <windows.h>#include <stdio.h> #include <Winsock2.h>#pragma comment(lib,"ws2_32")#define PORT 1129#define ADDRESS "127.0.0.1/socket.asp"int main(){ //加载winsock库WSADATA wsaData;WORD sockVersion = MAKEWORD(2,2);if(WSAStartup(sockVersion,&wsaData)!=0) return 0; //创建套接字SOCKET sClient = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);if(sClient==INVALID_SOCKET){ printf("socket error\n"); return 0;} //socket中装入远程地址信息SOCKADDR_IN remote;remote.sin_family = AF_INET;remote.sin_port = htons(1129);remote.sin_addr.S_un.S_addr = inet_addr(ADDRESS); if(connect(sClient,(SOCKADDR *)&remote,sizeof(SOCKADDR))==SOCKET_ERROR){ printf("connect error\n"); closesocket(sClient); return 0;} while(true){ char SendData[255]; int i,ch; for( i = 0; (i < 254) && ((ch = getchar()) != EOF) && (ch!='\n'); i++) SendData[i] = (char)ch; SendData[i] = '\n'; SendData[i+1] = '\0'; send(sClient,SendData,i+2,0);} closesocket(sClient);WSACleanup();return 0;}[/code]编译通不过,请指正下。
展开
展开全部
#include <windows.h> #include <stdio.h> #include <winsock.h> #pragma comment(lib,"ws2_32") #define PORT 1129 #define ADDRESS "127.0.0.1/socket.asp" int main() { WSADATA wsaData; WORD sockVersion = MAKEWORD(2,2); if(WSAStartup(sockVersion,&wsaData)!=0) return 0; SOCKET sClient = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP); if(sClient==INVALID_SOCKET) { printf("socket error\n"); return 0; } sockaddr_in remote; remote.sin_family = AF_INET; remote.sin_port = htons(1129); remote.sin_addr.s_addr = inet_addr(ADDRESS); if(connect(sClient,(SOCKADDR *)&remote,sizeof(SOCKADDR))==SOCKET_ERROR) { printf("connect error\n"); closesocket(sClient); return 0; } while(true) { char SendData[255]; int i,ch; for( i = 0; (i < 254) && ((ch = getchar()) != EOF) && (ch!='\n'); i++) SendData[i] = (char)ch; SendData[i] = '\n'; SendData[i+1] = '\0'; send(sClient,SendData,i+2,0); } closesocket(sClient); WSACleanup(); return 0; } //帮你修改了下...可编译过...VC6.0
Storm代理
2023-07-25 广告
2023-07-25 广告
StormProxies是一家国内优质海外HTTP代理商,拥有一个庞大的IP资源池,覆盖200多个地区,IP数量大且匿名度高。其优点还包括超高并发、稳定高效、技术服务等特点,同时提供HTTP、HTTPS以及SOCKS5协议支持。此外,Sto...
点击进入详情页
本回答由Storm代理提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询