Server.cpp : Defines the entry point for the console application.

#include "stdafx.h"
#include <WINSOCK2.H>
#include <iostream.h>
#pragma comment(lib,"ws2_32.lib")


int main(int argc, char* argv[])
{
 SOCKET m_sock;
 WSADATA wsaData;
 if (0 !=WSAStartup(MAKEWORD(2,2),&wsaData))
 {
  cout<<"加载套接字失败!\n";
  return 0;
 }
 m_sock = socket(AF_INET,SOCK_STREAM,0);
 if (m_sock==INVALID_SOCKET)
 {
  cout<<"socket失败!\n";
  return 0;
 }

    sockaddr_in baddr;
 baddr.sin_family=AF_INET;
 baddr.sin_port=htons(6789);
 baddr.sin_addr.S_un.S_addr=htonl(INADDR_ANY);
 if (SOCKET_ERROR==bind(m_sock,(sockaddr*)&baddr,sizeof(sockaddr_in)))
 {
  cout<<"bind失败!\n";
        closesocket(m_sock);
        WSACleanup();
  return 0;
 }
 if (SOCKET_ERROR == listen(m_sock,5))
 {
  cout<<"listen失败!\n";
        closesocket(m_sock);
        WSACleanup();
  return 0;
 }
 
 return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
// cudaPi.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include <stdio.h> #include <cuda.h> #include <math.h> #define NUM_THREAD 1024 #define NUM_BLOCK 1 __global__ void cal_pi(double *sum, long long nbin, float step, long long nthreads, long long nblocks) { long long i; float x; long long idx = blockIdx.x*blockDim.x+threadIdx.x; for (i=idx; i< nbin; i+=nthreads*nblocks) { x = (i+0.5)*step; sum[idx] = sum[idx]+4.0/(1.+x*x); } } int _tmain(int argc, _TCHAR* argv[]) { long long tid; double pi = 0; long long num_steps = 100000000; float step = 1./(float)num_steps; long long size = NUM_THREAD*NUM_BLOCK*sizeof(double); clock_t before, after; double *sumHost, *sumDev; sumHost = (double *)malloc(size); cudaMalloc((void **)&sumDev, size); // Initialize array in device to 0 cudaMemset(sumDev, 0, size); before = clock(); // Do calculation on device printf("Before Compute \n\n"); dim3 numBlocks(NUM_BLOCK,1,1); dim3 threadsPerBlock(NUM_THREAD,1,1); cal_pi <<<numBlocks, threadsPerBlock>>> (sumDev, (int)num_steps, step, NUM_THREAD, NUM_BLOCK); // call CUDA kernel printf("After Compute \n\n"); // Retrieve result from device and store it in host array cudaMemcpy(sumHost, sumDev, size, cudaMemcpyDeviceToHost); printf("After Copy \n\n"); for(tid=0; tid<NUM_THREAD*NUM_BLOCK; tid++){ pi = pi+sumHost[tid]; } pi = pi*step; after = clock(); printf("The value of PI is %15.12f\n",pi); printf("The time to calculate PI was %f seconds\n",((float)(after - before)/1000.0)); free(sumHost); cudaFree(sumDev); return 0; }
最新发布
06-12
// zuoye07.cpp : Defines the entry point for the console application. // #include "stdafx.h" #include "zuoye07.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif DWORD BufferSize=1024; char buf[1024]; / // The one and only application object CWinApp theApp; using namespace std; void FileReadWrite_NoBuffer(char*source,char*destination); int _tmain(int argc,TCHAR*angv[],TCHAR*envp[]) { int nRetCode=0; printf("Call FileReadWrite_NoBuffer!\n"); //调用FileReadWrite_NoBuffer(char*source,char*destination)函数 FileReadWrite_NoBuffer("source.txt","nobuffer.txt"); return nRetCode; } void FileReadWrite_NoBuffer(char*source,char*destination) { HANDLE handle_src,handle_dst; DWORD NumberOfByteWrite; bool cycle; char*buffer; buffer=buf; //创建文件source.txt handle_src=CreateFile(source, GENERIC_READ, 0, NULL, OPEN_ALWAYS, FILE_FLAG_NO_BUFFERING, NULL); //创建文件nobuffer.txt handle_dst=CreateFile(destination, GENERIC_WRITE, NULL, NULL, OPEN_ALWAYS, NULL, NULL); //判断文件是否创建失败,若失败打印输出提示信息并退出 if(handle_src==INVALID_HANDLE_VALUE || handle_dst==INVALID_HANDLE_VALUE) { printf("File Create Fail!\n"); exit(1); } cycle=true; while(cycle) { NumberOfByteWrite=BufferSize; //读取文件source.txt if(!ReadFile(handle_src,buffer,NumberOfByteWrite,&NumberOfByteWrite,NULL)) { //读取文件source.txt失败 printf("Read File Error!%d\n",GetLastError()); exit(1); } if(NumberOfByteWrite<BufferSize)cycle=false; //写入文件nobuffer.txt if(!WriteFile(handle_dst,buffer,NumberOfByteWrite,&NumberOfByteWrite,NULL)) { //写入文件nobuffer.txt失败 printf("Write File Error!%d\n",GetLastError()); exit(1); } } //关闭文件句柄(source.txt,nobuffer.txt) CloseHandle(handle_src); CloseHandle(handle_dst); }
06-09
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值