#include "winsock2.h"
#include "stdio.h"
#include "time.h"
#include <iostream>
#include <Ws2tcpip.h>
#include "stdafx.h"
#define MAX_BUFFER 1024
#define SERVER_PORT 5060
using namespace std;
int main(int argc, char* argv[])
{
SOCKET serverFd;
int connectionFd, i = 1;
struct sockaddr_in servaddr;
int in = 0;
char sendbuffer[MAX_BUFFER + 1];
char recvbuffer[MAX_BUFFER + 1];
WSADATA wsaData;
if (WSAStartup(MAKEWORD(2, 2), &wsaData) == SOCKET_ERROR) {
printf("Winsock error\n");
return -1;
}
serverFd = socket(AF_INET, SOCK_STREAM, 0);
if (serverFd == -1) {
printf("socket error!\n");
WSACleanup();
return -1;
}
memset(&servaddr, 0, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_addr.S_un.S_addr = htonl(INADDR_ANY);
servaddr.sin_port = htons(SERVER_PORT);
bind(serverFd, (struct sockaddr *)&servaddr, sizeof(servaddr));
listen(serverFd, 5);
while (1) {
connectionFd = accept(serverFd, (struct sockaddr *)NULL, NULL);
if (connectionFd >= 0) {
send(connectionFd, "HELLO", strlen("HELLO"), 0);
cout << "send success!" << endl;
}
if ((in = recv(connectionFd, recvbuffer, MAX_BUFFER, 0)) > 0) {
recvbuffer[in] = 0;
cout << "recv from client:" << recvbuffer << endl;
}
}
closesocket(connectionFd);
closesocket(serverFd);
WSACleanup();
return 0;
}
没有合适的资源?快使用搜索试试~ 我知道了~
VS2017实现Tcp socket通信(C++)
共203个文件
html:54个
lib:32个
tlog:24个
需积分: 49 195 下载量 84 浏览量
2019-04-22
14:01:40
上传
评论 13
收藏 69.79MB RAR 举报
温馨提示
包括服务器客户端程序,基于Visual Studio2017实现,编译测试过了,用到的朋友记得关闭SDL检查
资源推荐
资源详情
资源评论
收起资源包目录
VS2017实现Tcp socket通信(C++) (203个子文件)
configurations.autopkg 664B
configurations.autopkg 664B
ChangeLog 3KB
TCPServer.cpp 3KB
TCPClient.cpp 1KB
Browse.VC.db 77.89MB
Solution.VC.db 688KB
libpthread.dll 106KB
libpthread-stdcall.dll 106KB
libpthread.dll 104KB
libpthread-stdcall.dll 104KB
libpthread.dll 85KB
libpthread-stdcall.dll 85KB
libpthread-stdcall.dll 81KB
libpthread.dll 81KB
libpthread.dll 41KB
libpthread-stdcall.dll 41KB
libpthread.dll 41KB
libpthread-stdcall.dll 41KB
libpthread.dll 33KB
libpthread-stdcall.dll 33KB
libpthread.dll 33KB
libpthread-stdcall.dll 33KB
TCPServer.exe 67KB
TCPClient.exe 67KB
TCPServer.exe 39KB
TCPClient.exe 38KB
TcpClient.vcxproj.filters 1KB
TcpServer.vcxproj.filters 1KB
pthread.h 43KB
sched.h 5KB
semaphore.h 5KB
need_errno.h 3KB
stdafx.h 186B
stdafx.h 92B
PortabilityIssues.html 21KB
pthread_mutex_init.html 18KB
index.html 14KB
pthread_cond_init.html 13KB
pthread_attr_init.html 12KB
pthread_mutexattr_init.html 11KB
pthread_setcancelstate.html 9KB
pthread_setcanceltype.html 9KB
pthread_cancel.html 9KB
pthread_key_create.html 9KB
pthread_rwlock_init.html 8KB
sem_init.html 8KB
pthread_barrier_init.html 8KB
sched_setscheduler.html 8KB
pthread_spin_init.html 8KB
pthread_rwlock_rdlock.html 7KB
pthread_attr_setstackaddr.html 7KB
pthread_barrierattr_setpshared.html 7KB
pthread_cleanup_push.html 7KB
pthread_rwlockattr_setpshared.html 7KB
pthread_rwlock_timedrdlock.html 7KB
pthread_kill.html 7KB
pthread_barrier_wait.html 7KB
pthread_rwlock_timedwrlock.html 7KB
pthread_condattr_setpshared.html 7KB
pthread_setconcurrency.html 7KB
pthread_rwlock_wrlock.html 7KB
pthread_mutexattr_setpshared.html 6KB
pthread_rwlock_unlock.html 6KB
pthread_spin_lock.html 6KB
pthread_barrierattr_init.html 6KB
pthread_rwlockattr_init.html 6KB
pthread_attr_setstacksize.html 5KB
sched_getscheduler.html 5KB
pthread_spin_unlock.html 5KB
pthread_join.html 5KB
pthread_setschedparam.html 5KB
sched_get_priority_max.html 5KB
pthreadCancelableWait.html 4KB
pthread_create.html 4KB
pthread_condattr_init.html 4KB
sched_yield.html 4KB
pthread_detach.html 4KB
pthread_win32_attach_detach_np.html 4KB
pthread_once.html 3KB
pthread_timechange_handler_np.html 3KB
pthread_getunique_np.html 3KB
pthread_self.html 3KB
pthread_win32_test_features_np.html 3KB
pthread_delay_np.html 3KB
pthread_num_processors_np.html 3KB
pthread_getw32threadhandle_np.html 2KB
pthread_exit.html 2KB
pthread_equal.html 1KB
vc141.idb 355KB
vc141.idb 355KB
vc141.idb 331KB
vc141.idb 235KB
TCPServer.ilk 453KB
TCPClient.ilk 452KB
TCPServer.ilk 337KB
TCPClient.ilk 327KB
TCPSERVER.ipch 69.75MB
TCPCLIENT.ipch 69.5MB
TCPCLIENT.ipch 65MB
共 203 条
- 1
- 2
- 3
资源评论
ttangzr
- 粉丝: 7
- 资源: 17
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 《CKA/CKAD应试指南/从docker到kubernetes 完全攻略》学习笔记 第1章docker基础(1.1-1.4)
- 基于python实现的水下压缩空气储能互补系统建模仿真与经济效益分析+源代码+论文
- 华中科技大学-自然语言处理实验,Bi-LSTM+CRF的中文分词框架,并且利用基于深度学习的方法进行中文命名实体识别++源码报告
- 基于动态罚函数的铁路车流分配与径路优化模型python源码
- 鱼群算法求解组环问题python源码+文档说明
- 基于决策优化的多波束测深测线规划模型MATLAB代码
- 课程设计-基于python实现的多目标优化算法求解带时间窗的车辆路径规划问题+源代码+文档说明+界面截图+pptx
- 基于通信信号与通信系统的MATLAB仿真源码-课程设计
- 嵌入式-信号机制(概念,发送,定时,捕捉,SIGCHLD 信号实现回收子进程)
- c语言管理系统大一大二笔记
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功