LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-14-2010, 07:48 AM   #1
scheme
LQ Newbie
 
Registered: May 2009
Distribution: Ubuntu, Ubuntu Studio, Debian, Arch
Posts: 24

Rep: Reputation: 1
UDP light bulb - questions


Awhile ago I wanted to make a small program in C, but I scrapped it after a few tries and ugly/inefficient code I didn't myself understand anymore. For the record, I've only just started programming.

There was supposed to be a light bulb icon on two computers, when pressed it'd send a short UDP package to the other computer (ip address given from command line) which would light the light bulb on both ends.

I managed to make the network code (well they were server/client snippets copy-pasted from Berkeley Sockets wikipedia article) and SDL code work separately locally (I chose SDL because I was going to learn it later anyway) but I never managed to put them together. Most importantly I couldn't make the server/client work in the same program. After the intro, here's a few questions:

For above do I have to use two different sockets to handle the sending and receiving?
Can it be done without threading or would I have to put separate parts on threads or would it just make more sense that way (considering the server should be listening all the time to minimize the already possible packet losses from using UDP)?

Also if you have anything to say about the project idea, just go ahead.
 
Old 08-15-2010, 01:11 AM   #2
paulsm4
LQ Guru
 
Registered: Mar 2004
Distribution: SusE 8.2
Posts: 5,863
Blog Entries: 1

Rep: Reputation: Disabled
Hi -

Q: For above do I have to use two different sockets to handle the sending and receiving?

A: No, absolutely not. One socket can do both "sendto()" and "recvfrom()".

Q: Can it be done without threading?

A: Certainly

Q: Considering the server should be listening all the time to minimize the already possible packet losses from using UDP?

A: In this scenario, it doesn't sound like "packet loss" would really be an issue. If it were, the easiest solution is to implement a simple "ACK/Retry" protocol". Or switch from UDP datagrams to TCP connections.

Strong suggestion:
Read Beej's Guide to Network Programming:
http://beej.us/guide/bgnet/

'Hope that helps .. PSM
 
1 members found this post helpful.
Old 08-16-2010, 11:46 AM   #3
scheme
LQ Newbie
 
Registered: May 2009
Distribution: Ubuntu, Ubuntu Studio, Debian, Arch
Posts: 24

Original Poster
Rep: Reputation: 1
Thank you for the clear answers!

I wanted to use UDP for the (seemingly) easy implementation and low bandwith (this app is rather trivial afterall).
I'll read through the guide, I've stumbled into it when searching if I should use SDL_network or plain Berkeley Sockets. I find I don't know anything about programming networks. Time to start experimenting and reading more.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
How many forum members does it take to change a light bulb? Tinkster General 377 04-26-2015 02:13 PM
Arkeia-Light and USB tape backup questions kchakrak Linux - Software 0 11-19-2008 04:33 AM
Exploding light bulb! markhod General 21 02-24-2007 07:04 AM
Control Light Bulb using serial cable ElectroLinux Linux - General 10 05-26-2006 09:18 AM
Questions regarding UDP Buffer Size in 2.4.20-31.9smp crazy_abt_linux Programming 1 04-25-2006 01:16 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:10 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration