PDA

View Full Version : Socket programming, please help me!



nthung
26th May 2010, 08:08
My problem is that.
I need to develop a programming connect to server to get Video, but server request UserName, PassWord. I don't know how to slove this. I use QtcpSocket
thanks so much

wysota
26th May 2010, 08:42
Without knowing the transmission protocol nor your code there is nothing we can do for you.

nthung
26th May 2010, 08:48
thanks
this is my code

void Hello::connect(char* serverName, int port){
QTcpSocket socket;
socket.setProxy(QNetworkProxy(QNetworkProxy::Defau ltProxy, serverName,port,"userName","passWord"));
//socket.connectToHost(serverName,port);
if(socket.waitForConnected(6000)==true)
{
qDebug()<<"Successfully";
}
else{
qDebug()<<socket.errorString();
return;
}

if we don't have userName,passWord everyone can connect and get my private data?
thanks

tbscope
26th May 2010, 08:59
Still not enough information. What kind of protocol do you want to use? Http, Ftp, Nntp, ... ?

nthung
26th May 2010, 09:11
Still not enough information. What kind of protocol do you want to use? Http, Ftp, Nntp, ... ?

TCP
thanks

tbscope
26th May 2010, 09:18
No, what do you use on top of TCP?

wysota
26th May 2010, 09:19
TCP
This is transport protocol. We are asking for application protocol.

nthung
26th May 2010, 09:22
No, what do you use on top of TCP?

thanks, i dont konw more, but with my code do you fix it for me?
I think the top of TCP used is FTP
thanks and i have you fix my code
thanks agian

wysota
26th May 2010, 09:31
thanks, i dont konw more, but with my code do you fix it for me?
I think the top of TCP used is FTP
thanks and i have you fix my code

We will not fix your code. You didn't provide enough information. Even if you did, we would still not fix your code but instead help you fix your own code. But this is meaningless since you don't even know what you are doing...

nthung
26th May 2010, 09:39
We will not fix your code. You didn't provide enough information. Even if you did, we would still not fix your code but instead help you fix your own code. But this is meaningless since you don't even know what you are doing...
i think that protocol is FTP
thanks

wysota
26th May 2010, 09:45
i think that protocol is FTP
Then I think you may want to use some higher level class such as QNetworkAccessManager or QFtp instead of QTcpSocket as I think you know FTP protocol requires at least two sockets.

nthung
26th May 2010, 09:53
Then I think you may want to use some higher level class such as QNetworkAccessManager or QFtp instead of QTcpSocket as I think you know FTP protocol requires at least two sockets.

yes but i have to use QTcpSocket
thanks, fix it for me
thanks agian

Archimedes
26th May 2010, 10:05
thanks, fix it for me


I don't know if this is a homework or not but this quote from C++ FAQ LITE (http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.2) gives the general idea:

"If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm."

Read the documentation then do it yourself. If you get stuck, ask a specific question!!!

nthung
26th May 2010, 10:15
I don't know if this is a homework or not but this quote from C++ FAQ LITE (http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.2) gives the general idea:

"If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm."

Read the documentation then do it yourself. If you get stuck, ask a specific question!!!

thanks but i am a programmer, i have been working for 2 years, i graduated since 2006 at PTIT in Vietnam
my leader requests me that convert a VC++ project to Qt project, i am new to Qt
thanks

wysota
26th May 2010, 11:14
thanks but i am a programmer, i have been working for 2 years, i graduated since 2006 at PTIT in Vietnam
my leader requests me that convert a VC++ project to Qt project, i am new to Qt
thanks

And your leader told you you had to use a bare QTcpSocket for FTP? Or did your leader tell you he *thought* the protocol in use was FTP? Maybe you should present him the paragraph from C++ FAQ Lite, especially the part about doing projects together? :)

squidge
26th May 2010, 11:17
Then you need to figure out how the VC++ project uses FTP, and see if you can replace that code with QFTP class. Once you have done that research, if it does not work for you, state why and maybe we can help.

nthung
26th May 2010, 17:27
And your leader told you you had to use a bare QTcpSocket for FTP? Or did your leader tell you he *thought* the protocol in use was FTP? Maybe you should present him the paragraph from C++ FAQ Lite, especially the part about doing projects together? :)

My leader tells me the problem, then i consider mysefl to slove.
Really, this is the first time i program about Socket, althought that i leanrt about socket programming in University before, so i dont clearly understand about TCP's working fundation
thanks

wysota
26th May 2010, 20:01
My leader tells me the problem, then i consider mysefl to slove.
So who asked you to use QTcpSocket?

squidge
26th May 2010, 22:03
So who asked you to use QTcpSocket?I'm assuming, the Visual Studio project. 1 -> 1 conversion.

wysota
26th May 2010, 22:39
If this program indeed uses FTP (which is yet to be confirmed, as the author only thinks it does), I strongly doubt they used bare sockets for this and not some Windows library for handling the protocol.

squidge
26th May 2010, 22:46
You are assuming they are sane. At lot of companies and people are not. Where I work, there are some people who prefer to reinvent the wheel rather than just using a perfectly good one someone else has made.

There reasoning? "If I find bugs, I can fix my own easily. Someone elses I would have to figure out how it worked first."

They fail to see that there freshly written code stands to have more bugs than the code that has been used for the past 5 years by other engineers, or the fact that there new version will be thrown out at the next code review...

wysota
26th May 2010, 23:01
You are assuming they are sane.
Well... yes, that's true. I'm assuming that if they used bare sockets we would be presented with a bit more code than those few lines. It looks like code written from scratch ("ok, I connected, now what?")


Where I work, there are some people who prefer to reinvent the wheel rather than just using a perfectly good one someone else has made.
Same here.