Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to decode from socket... #3

Open
Gaojianli opened this issue Mar 2, 2021 · 2 comments
Open

How to decode from socket... #3

Gaojianli opened this issue Mar 2, 2021 · 2 comments

Comments

@Gaojianli
Copy link

Gaojianli commented Mar 2, 2021

Hello, thanks for your excellent working... I am trying to develop a file server by using this project, but it is a little confusing about how to decode the file from the socket. I write the following code but it seems not working:

char buf[500]
int ret = 0;
int session_num=0;
int index = 0;
while (ret == 0){
        read(sockfd,buf,500);
        ret = m_lt_code->receiveAndDecode(200,buf,session_num,index);
}
m_lt_code->WriteFile("/tmp/test.png",session_num);

Could you please give me a example? Thanks!

@Neo-ZK
Copy link
Owner

Neo-ZK commented Mar 2, 2021

抱歉,这部分代码我很久没维护了,鉴于我当时的水平,这些代码也只是个半成品,我最近没什么时间重构这个,只能给你一些实现上的建议:

  1. 我提供了一个send_callback,其实你只需要自己基于这个call back实现一个socket发送就好了
  2. 构造函数里是直接输入一个文件,其实从通用性来讲,最好是一个buf,以及lt的码长之类的一系列参数
  3. 如果在socket层面做这个事情,LT的编解码其实是需要配合网络协议来的,你需要自己设计ack机制,比如成功解码后接收端恢复确认信息,或者只是简单仿真性能比如服务端只发送一定数量的数据包,看client是否成功恢复

如果你愿意帮忙完善这部分代码,欢迎提pr,不胜感激

@Gaojianli Gaojianli changed the title How to encode from socket... How to decode from socket... Mar 3, 2021
@Gaojianli
Copy link
Author

抱歉,这部分代码我很久没维护了,鉴于我当时的水平,这些代码也只是个半成品,我最近没什么时间重构这个,只能给你一些实现上的建议:

  1. 我提供了一个send_callback,其实你只需要自己基于这个call back实现一个socket发送就好了
  2. 构造函数里是直接输入一个文件,其实从通用性来讲,最好是一个buf,以及lt的码长之类的一系列参数
  3. 如果在socket层面做这个事情,LT的编解码其实是需要配合网络协议来的,你需要自己设计ack机制,比如成功解码后接收端恢复确认信息,或者只是简单仿真性能比如服务端只发送一定数量的数据包,看client是否成功恢复

如果你愿意帮忙完善这部分代码,欢迎提pr,不胜感激

不好意思,写错了,我的问题是如何解码。现在我用一个socket把数据发送出来了了,那么在另一个程序中,我该如何解码数据呢,LTcode对象如何构造呢,receiveAndDecode的后两个参数又应该怎么填写呢,当receiveAndDecode返回1了的时候是不是就可以写会了,writeFile的第二个参数line_num什么意思呢?
抱歉,问题有点多,还望解惑

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants