PDA

View Full Version : socket programming



Arpitgarg
7th March 2011, 06:26
hey I m new to network programming.C an any one suggest some examples /material for programming..

unit
7th March 2011, 07:25
Good starter example priveded by QT. See example section of QT documentation.

ChrisW67
7th March 2011, 08:01
If you are after Qt network programming resources: open Qt Assistant select "Network Programming from the front page of the Qt Reference documentation. Also look at the Qt examples.

posixprogrammer
7th March 2011, 10:56
Hi friend,
About socket programming, I used to do with UDP and TCP.
With UDP, server must have one socket to communicate, it looks like:
while(1)
{
int bytes_read = recvfrom(sd, buffer, sizeof(buffer), 0, 0, 0);
}
You can find out it on internet, so much example for it.

With TCP, server must have one socket to communicate, and you should find out what is "listen", and "accept" functions.

With both, you need to know multi-thread, may be POSIX thread or Win32 thread, depend on your OS which you do on.

With them( UDP/TCP, thread) you can create a simple client-server.

If you want to be good about socket programming, the first do no care about Qt thread, Java thread, C# thread. Let's start with APIs of OS to create thread as: pthread_create ( UNIX-Like), CreateThread( Win32).
Good luck!

squidge
7th March 2011, 11:50
If you use Qt, there is no need for multiple thread, blocking calls or infinite loops. Everything can be done with signals and slots. This makes it much easier than using platform specific calls, and of course means your application runs under multiple platforms with a minimum of effort.

Arpitgarg
7th March 2011, 17:13
Thanks, but but i am completely clueless about TCP/UDP programming.
I tried using documentation,but was'nt of much help.
can u suggest an example or material for it.

Thanks
Arpit

squidge
7th March 2011, 18:50
What didn't you understand about the documentation?

Did you look at the examples? Eg. fortuneclient, fortuneserver, etc?

marco.stanzani
21st March 2011, 11:12
If you want to be good about socket programming, the first do no care about Qt thread, Java thread, C# thread. Let's start with APIs of OS to create thread as: pthread_create ( UNIX-Like), CreateThread( Win32).

ciao posixprog
why you discourage using Qthreads? are there problems using Qt networking inside a Qt thread?
thanks

squidge
21st March 2011, 12:35
There's no need to use Qt networking within Qt threads, as Qt networking is event-driven.

marco.stanzani
21st March 2011, 13:08
thanks, but i am designing a client which communicates through two different IP ports (same IP address) doing different activities. i was thinking to encapsulate two ip soclkets inside two separate Qthread: do you see anything wrong with this?

squidge
21st March 2011, 17:44
I don't see why that requires two QThreads. One possible reason would be that you are going to be doing processor intensive operations taking several seconds to compute each time, but even then you could just put the processor intensive task itself in a thread, and have the socket operations in the standard event loop.

Even if you are handling 100 connections, you can still do the task easily in a single thread.

posixprogrammer
21st April 2011, 07:39
Hi all,
I don't want to discourage anyone about using Qt Thread. But I think that they need to know about thread more (each of specific OS), before using Qt Thread, and Qt Framework is great tool to do on cross OS.
Best regards

mcosta
21st April 2011, 07:53
Hi, I partially agree with you.
It's true that any programmer have to know problems of the multi-threading programming.

Recently the new C++ C++0X standard introduced multiplatform thread facilities.
Before that many multiplatform C++ libraries/framework like Qt, ACE, boost provides similar tools.

Native API are necessary only in very specific platform dependent problems

posixprogrammer
21st April 2011, 09:25
Hi all,
On our way from A to Z, often we need to pass B, C, D.... Understanding native APIs ( OS principle) may be middle point, not end point, but we must pass. I also use Qt for my application, but I still know native APIs, just be fun, happy, knowledge.
The time is to know simple native APIs no more understand Qt APIs.
Qt is great and will go on, I agree with this.
Best regards!!!