套接字发送二进制文件(Jpeg) [英] Socket Send Binary (Jpeg)

查看:107
本文介绍了套接字发送二进制文件(Jpeg)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了一个程序,它将使用winsock同时发送text / html文件

作为jpegs。我的代码可以找到文本,但不会使用jpegs来使用
。我的代码如下。我错过了什么?可以有人

指向我正确的方向。


ifstream文件;

file.open(r.c_str(), ios :: binary);

char buffer [1024] ="" ;;

int BytesSent = 0;

int BytesIndex = 0 ;

while(!file.eof()){

file.read(buffer,1024);

int BytesLeft = strlen(buffer );

while(BytesLeft!= 0){

BytesSent = send(sock,& buffer [BytesIndex],BytesLeft,0);

BytesLeft - = BytesSent;

BytesIndex + = BytesSent;

cout<<缓冲区<<结束;

}

}

I writing a program that will send both a text/html document as well
as jpegs using winsock. My code works find for the text, but will not
work with jpegs. My code is below. What am I missing? Can someone
point me in the right direction.

ifstream file;
file.open(r.c_str(), ios::binary);
char buffer[1024] = "";
int BytesSent = 0;
int BytesIndex = 0;
while( !file.eof() ) {
file.read(buffer, 1024);
int BytesLeft = strlen(buffer);
while(BytesLeft != 0){
BytesSent = send(sock, &buffer[BytesIndex], BytesLeft, 0);
BytesLeft -= BytesSent;
BytesIndex +=BytesSent;
cout << buffer << endl;
}
}

推荐答案

* iwasinnihon:
* iwasinnihon:

我编写的程序将同时发送text / html文件

作为使用winsock的jpegs。我的代码可以找到文本,但不会使用jpegs来使用
。我的代码如下。我错过了什么?可以有人

指向我正确的方向。


ifstream文件;

file.open(r.c_str(), ios :: binary);

char buffer [1024] ="" ;;

int BytesSent = 0;

int BytesIndex = 0 ;

while(!file.eof()){

file.read(buffer,1024);

int BytesLeft = strlen(buffer );
I writing a program that will send both a text/html document as well
as jpegs using winsock. My code works find for the text, but will not
work with jpegs. My code is below. What am I missing? Can someone
point me in the right direction.

ifstream file;
file.open(r.c_str(), ios::binary);
char buffer[1024] = "";
int BytesSent = 0;
int BytesIndex = 0;
while( !file.eof() ) {
file.read(buffer, 1024);
int BytesLeft = strlen(buffer);



这里。

Here.


while(BytesLeft!= 0){

BytesSent = send(sock,& buffer [BytesIndex],BytesLeft,0);

BytesLeft - = BytesSent;

BytesIndex + = BytesSent;

cout<<缓冲区<<结束;

}

}
while(BytesLeft != 0){
BytesSent = send(sock, &buffer[BytesIndex], BytesLeft, 0);
BytesLeft -= BytesSent;
BytesIndex +=BytesSent;
cout << buffer << endl;
}
}



-

答:因为它弄乱了人们通常阅读文字的顺序。

问:为什么这么糟糕?

A:热门帖子。

问:usenet和电子邮件中最烦人的事情是什么?


--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?


我错过了什么吗?你告诉我什么?


2月21日晚上7点45分,Alf P. Steinbach < a ... @ start.nowrote:
Am I missing something? What are you telling me?

On Feb 21, 7:45 pm, "Alf P. Steinbach" <a...@start.nowrote:

* iwasinnihon:
* iwasinnihon:

我写一个程序这将使用winsock发送文本/ html文档以及

作为jpegs。我的代码可以找到文本,但不会使用jpegs来使用
。我的代码如下。我错过了什么?可以有人

指向我正确的方向。
I writing a program that will send both a text/html document as well
as jpegs using winsock. My code works find for the text, but will not
work with jpegs. My code is below. What am I missing? Can someone
point me in the right direction.


ifstream file;

file.open(r.c_str(),ios :: binary);

char buffer [1024] ="" ;;

int BytesSent = 0;

int BytesIndex = 0;

while(!file.eof()){

file.read(buffer,1024);

int BytesLeft = strlen(buffer);
ifstream file;
file.open(r.c_str(), ios::binary);
char buffer[1024] = "";
int BytesSent = 0;
int BytesIndex = 0;
while( !file.eof() ) {
file.read(buffer, 1024);
int BytesLeft = strlen(buffer);



这里。


Here.


while(BytesLeft!= 0){

BytesSent = send(sock,& buffer [BytesIndex],BytesLeft,0);

BytesLeft - = BytesSent;

BytesIndex + = BytesSent;

cout<<缓冲区<<结束;

}

}
while(BytesLeft != 0){
BytesSent = send(sock, &buffer[BytesIndex], BytesLeft, 0);
BytesLeft -= BytesSent;
BytesIndex +=BytesSent;
cout << buffer << endl;
}
}



-

答:因为它弄乱了人们通常阅读文字的顺序。

问:为什么这么糟糕?

A:热门帖子。

问:usenet和电子邮件中最烦人的事情是什么?


--
A: Because it messes up the order in which people normally read text.
Q: Why is it such a bad thing?
A: Top-posting.
Q: What is the most annoying thing on usenet and in e-mail?



iwasinnihon写道:


请不要发帖。
iwasinnihon wrote:

Please don''t top-post.

2月21日晚上7:45,Alf P. Steinbach < a ... @ start.nowrote:
On Feb 21, 7:45 pm, "Alf P. Steinbach" <a...@start.nowrote:

>> * iwasinnihon:

>>* iwasinnihon:


>>>我编写的程序将使用winsock同时发送文本/ html文档作为jpegs。我的代码可以找到文本,但不会使用jpeg。我的代码如下。我错过了什么?有人可以指出我正确的方向。
>>>I writing a program that will send both a text/html document as well
as jpegs using winsock. My code works find for the text, but will not
work with jpegs. My code is below. What am I missing? Can someone
point me in the right direction.


>>> ifstream文件;
file.open(r.c_str(),ios :: binary);
char buffer [1024] ="" ;;
int BytesSent = 0;
int BytesIndex = 0;
while(!file.eof()){
file.read(buffer,1024);
int BytesLeft = strlen(buffer);
>>>ifstream file;
file.open(r.c_str(), ios::binary);
char buffer[1024] = "";
int BytesSent = 0;
int BytesIndex = 0;
while( !file.eof() ) {
file.read(buffer, 1024);
int BytesLeft = strlen(buffer);


这里。


Here.



我错过了什么吗?你告诉我什么?

Am I missing something? What are you telling me?



查看strlen特别注意它所期望的

参数。


-

Ian Collins。

Look up strlen paying particular attention to what it expects as its
parameter.

--
Ian Collins.


这篇关于套接字发送二进制文件(Jpeg)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆