I am creating a multithreaded socket program that needs to send 2 sets of data to the server periodically. The client needs to send GPS information every 3 seconds and polarity information every 4 seconds. My idea on implementing this was to simply create a new thread, make a infinite loop, send() the GPS information, sleep() for 1 second, send() the polarity information, and then sleep() for 2 seconds. Would this be a sufficient way of going about this? Sorry, I'm new to socket programming so I don't know of any alternative methods.
Sending data periodically from client to server in C
1.7k Views Asked by marcusc At
1
There are 1 best solutions below
Related Questions in C
- Passing arguments to main in C using Eclipse
- kernel module does not print packet info
- error C2016 (C requires that a struct or union has at least one member) and structs typedefs
- Drawing with ncurses, sockets and fork
- How to catch delay-import dll errors (missing dll or symbol) in MinGW(-w64)?
- Configured TTL for A record(s) backing CNAME records
- Allocating memory for pointers inside structures in functions
- Finding articulation point of undirected graph by DFS
- C first fgets() is being skipped while the second runs
- C std library don't appear to be linked in object file
- gcc static library compilation
- How to do a case-insensitive string comparison?
- C programming: Create and write 2D array of files as function
- How to read a file then store to array and then print?
- Function timeouts in C and thread
Related Questions in SOCKETS
- Drawing with ncurses, sockets and fork
- UDP sockets in C not working
- How can I send multiple objects over one socket in java?
- psuedo TCP multicast with os.dup2() in python?
- My get request for http is very slow
- Nodejs connect mysql socket to another host?
- HttpRequestContext vs HttpContext
- Spring based client server communication without network
- Java does not accept 2 methods with same name
- Retrieve Data From EOC(Eithernet Over coxial) device
- Ping a server without freezing the Thread
- C sockets: Exit client after all data is received
- What is the best way to send XML converted to a byte array over TCP, then translate the response back to readable XML?
- C# Winform to Connect to Device Using IP
- Java Restart a Socket
Related Questions in SLEEP
- Delphi and sleep function
- Clear labels, Images in WatchKit after didDeactivate (Glance and InterfaceController)
- Php schedule run a function after 10 minutes
- How to change the delay of sleep/timer thread in android during runtime?
- Compile error on linux (a simple demo code on concept of pipe)
- Timeout handle email php
- Running delayed jobs in loop
- Explain behavior of Unix sleep() function executed on Android
- Sleep Shiny WebApp to let it refresh... Any alternative?
- Will process lost wake-up chance in a preemptive kernel?
- Does sleep/nanosleep work by utilizing a busy wait scheme?
- Python time.sleep on line 2 happens before line 1
- VBS - How to pause a script until a key is pressed?
- How to keep track of time in python without sleeping?
- Sleeping the time difference
Related Questions in SERVER
- How can I monitor an endpoint's status with Ruby?
- Rasterization with Javascript looks different on Apache server
- Netty loses udp packets at the beginning of the communication
- How to have Heroku build my development branch on a staging server?
- Timing packets on a traffic server
- copying file from local machine to Ubuntu 12.04 returning permission denied
- AWS EC2: Migrating from Windows to Linux Server
- Connecting Ms Access Db to Mysql through Vba
- Remove ".local" suffix on local server (Yosemite)
- Server program gets stuck at accept function
- PayPal API QueryParameters not found
- Python Server - Processing WebSocket.close()
- NameValuePair, HttpParams, HttpConnection Params deprecated on server request class for login app
- Unable to send file from ftp to another ftp
- Scala - TCP Packet frame using Akka
Related Questions in PERIOD
- How to compare two java.time.Period in java 8?
- Calculating highest high price during specific period using quantmod in R
- java.time.Period , dividing the period gives wrong results
- Why do I get wrong dates after the second year when use aggregate?
- Parsing the ISO-8601 duration values of the AMAZON.DURATION slot type
- SQL Count different timeframes over a known period
- RewriteRule .? only for one or more chars?
- R create multiple ranges of dates in tidyverse
- autocorrelation to detect periodicity
- Compare a date in a given period
- Binding to fields containing a period in DataTable in C#/WPF
- mysql difference in month as column in where clause
- Period in javascript variable throwing error I can't seem to squash
- Period in regex using java
- C++ Call Function Periodically in Microseconds Range
Trending Questions
- UIImageView Frame Doesn't Reflect Constraints
- Is it possible to use adb commands to click on a view by finding its ID?
- How to create a new web character symbol recognizable by html/javascript?
- Why isn't my CSS3 animation smooth in Google Chrome (but very smooth on other browsers)?
- Heap Gives Page Fault
- Connect ffmpeg to Visual Studio 2008
- Both Object- and ValueAnimator jumps when Duration is set above API LvL 24
- How to avoid default initialization of objects in std::vector?
- second argument of the command line arguments in a format other than char** argv or char* argv[]
- How to improve efficiency of algorithm which generates next lexicographic permutation?
- Navigating to the another actvity app getting crash in android
- How to read the particular message format in android and store in sqlite database?
- Resetting inventory status after order is cancelled
- Efficiently compute powers of X in SSE/AVX
- Insert into an external database using ajax and php : POST 500 (Internal Server Error)
Popular Questions
- How do I undo the most recent local commits in Git?
- How can I remove a specific item from an array in JavaScript?
- How do I delete a Git branch locally and remotely?
- Find all files containing a specific text (string) on Linux?
- How do I revert a Git repository to a previous commit?
- How do I create an HTML button that acts like a link?
- How do I check out a remote Git branch?
- How do I force "git pull" to overwrite local files?
- How do I list all files of a directory?
- How to check whether a string contains a substring in JavaScript?
- How do I redirect to another webpage?
- How can I iterate over rows in a Pandas DataFrame?
- How do I convert a String to an int in Java?
- Does Python have a string 'contains' substring method?
- How do I check if a string contains a specific word?
Your proposed scheme is:
Over a period of 12 seconds, that leads to:
This sends the GPS information 4 times (correct) and the polarity 4 times, and every 3 seconds, not 3 times and every 4 seconds as the specification requires. The desired sequence might be:
Note that in some second, both GPS and polarity must be sent.
You can achieve this in either of two ways. Assuming you need to use threads at all, use two threads, one on a three second wait, one on a four second wait. Coordinate access to the socket with a mutex so that on multiples of 12 seconds, you still get sane behaviour.
However, you could do it all with a single-threaded process that waits appropriate intervals:
You can also sleep for multiple seconds by altering the code at the end of the loop to determine which send comes next and sleeping for the appropriate amount of time and incrementing
t_curby the appropriate amount of time (rather than just using 1 second all the time).If you need to avoid drift (because the code above assumes that the send process is instantaneous and it isn't), then you have to use sub-second sleeps and trap the time at the start of the loop and adjust the sleep interval to allow for the time taken to do the sending.