android socket 分包,:关于socket 分包的解决方法

该博客介绍了如何处理Android中使用Socket通信时遇到的数据分包问题。通过创建C++服务器端程序展示TCP连接和接收过程,同时在客户端,当接收到部分数据时,通过搜索特定分隔符来重组完整消息。
摘要由CSDN通过智能技术生成

C/C++ code// Server.cpp : create a console application, and include the sources in the project

//

// 1. open the *.c in the Visual C++, then "rebuild all".

// 2. click "yes" to create a project workspace.

// 3. You need to -add the library 'ws2_32.lib' to your project

// (Project -> Properties -> Linker -> Input -> Additional Dependencies)

// 4. recompile the source.

#include "stdafx.h"

#include

#include

#include

#include

#include

#define DEFAULT_PORT 5019

int find(char s[],char t[]);

void accept_conn(void *dummy);

SOCKET sock,new_socket;

int main(int argc, char **argv){

int addr_len;

struct sockaddr_in local, client_addr;

WSADATA wsaData;

if (WSAStartup(0x202, &wsaData) == SOCKET_ERROR){

// stderr: standard error are printed to the screen.

fprintf(stderr, "WSAStartup failed with error %d\n", WSAGetLastError());

//WSACleanup function terminates use of the Windows Sockets DLL.

WSACleanup();

return -1;

}

// Fill in the address structure

local.sin_family = AF_INET;

local.sin_addr.s_addr = INADDR_ANY;

local.sin_port = htons(DEFAULT_PORT);

sock = socket(AF_INET,SOCK_STREAM, 0); //TCp socket

if (soc

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值