问题描述
- 关于visual studio 的问题
-
这里有个关于visual studio的问题,c++语言,win32控制台应用程序,调试不出来,求大神们解答
// 162.cpp : 定义控制台应用程序的入口点。
//#include "stdafx.h"
#include "iostream"
#include "winsock2.h"
#include "fstream"
#include "process.h"
#define PORT 65432
#pragma comment(lib,"ws2_32.lib")
using namespace std;
char Command[20];
char filename[128];
char fname[128];
ifstream inFile;
unsigned int _stdcall GetCommand(void *par);
unsigned int _stdcall SendFlie(void *par);int _tmain(int argc, _TCHAR* argv[])
{
/******定义相关变量*******/
int sock_server;
struct sockaddr_in addr,client_addr;
unsigned hThread1,hThread2;
unsigned int ThreadID1,ThreadID2;
int addr_len=sizeof(struct sockaddr_in);
cout<<"请输入要发送的文件名:
";
cin>>filename;
/*******以二进制打开要分发的文件********/
inFile.open(filename,ios::in|ios::binary);
if(!inFile.is_open())
{
cout<<"Cannot open "<
return 0;
}
/*********截取发送给客户端的文件名*********/
int len=strlen(filename);
int i=len;
while(filename[i]!=''&&i>=0)
i--;
if(i<0)
i=0;
else
i++;
int m=0;
while(filename[m+i]!='')
{
fname[m]=filename[m+i];
m++;
}
/*******初始化winsock DLL******/
WSADATA wsaData;
WORD wVersionRequested=MAKEWORD(2,2);
if(WSAStartup(wVersionRequested,&wsaData)!=0)
{
cout<<"加载winsock.DLL失败!
";
return 0;
}
/******创建套接字*****/
if((sock_server=socket(AF_INET,SOCK_STREAM,0))<0)
{
cout<<"创建套接字失败!
";
WSACleanup();
return 0;
}
/*****设置套接字为非阻塞模式*****/
unsigned long ul=1;
int nRet=ioctlsocket(sock_server,FIONBIO,(unsigned long )&ul);
if(nRet==SOCKET_ERROR)
{
cout<<"设置套接字选项失败!
";
closesocket(sock_server);
WSACleanup();
return 0;
}
/*****绑定IP接口******/
memset((void )&addr,0,addr_len);
addr.sin_family =AF_INET;
addr.sin_port =htons(PORT);
addr.sin_addr.s_addr=htonl(INADDR_ANY);
if(bind(sock_server,(LPSOCKADDR)&addr,sizeof(addr))!=0)
{
cout<<"绑定IP地址失败!
";
closesocket(sock_server);
WSACleanup();
return 0;
}
/****开始监听*****/
if(listen(sock_server,5)!=0)
{
cout<<"listen函数调用失败!
";
closesocket(sock_server);
WSACleanup();
return 0;
}
else
cout<<"listenning......
";
/*****启动命令接收线程******/
hThread1=_beginthreadex(NULL,0,GetCommand,(LPVOID)Command,0,&ThreadID1);
/******接收并处理客户连接*****/
SOCKET newsock;
while(1)
{
if(strcmp(Command,"close")==0) break;
newsock=accept(sock_server,(LPSOCKADDR)&client_addr,&addr_len);
if(newsock!=INVALID_SOCKET)
{
cout<<"connect from "<<inet_ntoa(client_addr.sin_addr)<<endl;
hThread2=_beginthreadex(NULL,0,SendFile,(LPVOID)newsock,0,&ThreadID2);
}
}
inFile.close();
closesocket(sock_server);
return 0;
}
unsigned int _stdcall SendFile(void par)
{
char buffer[1000];
SOCKET sock=(SOCKET)par;
/****设置套接字为阻塞模式******/
unsigned long ul=0;
int nRet=ioctlsocket(sock,FIONBIO,(unsigned long )&ul);
send(sock,(char *)fname,strlen(fname)+1,0);
int size=recv(sock,buffer,sizeof(buffer),0);
if(strcmp(buffer,"OK")!=0)
{
cout<<"客户端出错!
";
closesocket(sock);
return 0;
}
/****传输文件内容******/
while(!inFile.eof())
{
inFile.read(buffer,sizeof(buffer));
//size=inFile.gcount ();
send(sock,(char )buffer,size,0);
}
cout<<"文件传输结束!
";
closesocket(sock);
return 0;
}
/*****从键盘接收命令的线程函数********/
unsigned int _stdcall GetCommand(void *par)
{
char *p=(char *)par;
while(strcmp(p,"close")!=0)
gets(p);
return 0;
}
解决方案
看下防火墙的配置,系统设置等等。
解决方案二:
1。关闭Windows防火墙。
2。确认通信双方之间能够被路由。简单说就是同一个局域网,或者说一个在公网一个在局域网,或者都在公网。如果是两个局域网直接就必须用端口映射或其他方法。
3。用抓包软件分析
解决方案三:
关于Visual Studio2010字符集的问题
Visual Studio 2013 class颜色问题
解决 visual studio cocos2d-x 3.x 下 Scale9Sprite 的问题