473,396 Members | 1,765 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

UDP Select() TCP

hi. ok my problem is that i have been using TCP for a while and now i want to change to UDP. Im using the select I/0 method.

i have a listening thread like this :
Expand|Select|Wrap|Line Numbers

1. void Server::vListeningThread( LPVOID pParam )
2. {
3. Server *pServer = (Server*)pParam;
4. SOCKET socketClient;
5. do
6. {
7. socketClient = accept( *pServer->p_socketServer, 0, 0 );
8.
9. if ( socketClient == SOCKET_ERROR || pServer->usNumberOfClients >= pServer->usMAX_CLIENTS )
10. {
11. // send an error code to client //////////////////////////////////////
12. closesocket( socketClient );
13. }
14. else
15. {
16. WaitForSingleObject( pServer->handleMutex, INFINITE );
17. FD_SET( socketClient, &pServer->fdsetMaster );
18. ReleaseMutex( pServer->handleMutex );
19. pServer->usNumberOfClients++;
20. }
21.
22. }while( pServer->bConnected );
23.
24. }



now im unsure how to change it into UDP.

does the new socket of data that has been sent go straight into the FD_SET? Therefore when im polling through the set i would have to check if it has been set or not?

Please help, im a little bit confused with this?

thanks
Nov 9 '08 #1
3 7037
TCP version:

Expand|Select|Wrap|Line Numbers
  1. Server *pServer = (Server*)pParam;
  2.     SOCKET socketClient;
  3.     do
  4.     {
  5.         socketClient = accept( *pServer->p_socketServer, 0, 0 );
  6.  
  7.         if ( socketClient == SOCKET_ERROR || pServer->usNumberOfClients >= pServer->usMAX_CLIENTS ) 
  8.         {
  9.             // send an error code to client //////////////////////////////////////
  10.             closesocket( socketClient );
  11.         }
  12.         else 
  13.         {
  14.             WaitForSingleObject( pServer->handleMutex, INFINITE );
  15.             FD_SET( socketClient, &pServer->fdsetMaster );
  16.             ReleaseMutex( pServer->handleMutex );
  17.             pServer->usNumberOfClients++;
  18.         }
  19.  
  20.     }while( pServer->bConnected );
and then later
Expand|Select|Wrap|Line Numbers
  1. int SelectResult = select( 0, &fdsetPolling, NULL, NULL, &timevalWait );
  2.  
  3.             if ( SelectResult || SelectResult != SOCKET_ERROR ) 
  4.             {
  5.                 for ( USHORT usLoop = 0; usLoop < fdsetPolling.fd_count; usLoop++ ) 
  6.                 {
  7.                     ///** ok everythings is ok.  Now to get the socket with new data **//////
  8.                     C_PacketData.vSetSocketData( fdsetPolling.fd_array[ usLoop ] );
  9.  
  10.                     ///** hnow receiver the data from that socket **//////
  11.                     int Retrieved = recv( tempSocket, (char*)&C_PacketData, pServer->uPACKET_SIZE, 0 );
  12. }
  13. }
so for UDP i would i just delete the first part and for the second part i would add in this

FS_ISSET( fdsetPolling.fd_array[ usLoop ], fdsetPolling )

before i call C_PacketData.vSetSocketData( fdsetPolling.fd_array[ usLoop ] );

correct me if im wrong or missing out something?

thanks
Nov 10 '08 #2
Banfa
9,065 Expert Mod 8TB
Sorry I've been holding off because on the whole I only use TCP sockets so I am not so familiar with UDP.

I see nothing about the select(...) function that precludes using it on a UDP socket. Clear since UDP is connectionless you can not accept(...) a connection.

A good place to start may be the Wikipedia article on Berkley sockets..
Nov 10 '08 #3
thank you, much appreciated.
Nov 10 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: JT | last post by:
I have an input form for which I've created a "matrix" for user input. Basically, the user chooses a radio button and then through javascript, a select box is displayed to define a value for that...
4
by: Elroyskimms | last post by:
Using SQL 2000... tblCustomer: CustomerID int CompanyName varchar(20) HasRetailStores bit HasWholesaleStores bit HasOtherStores bit tblInvoiceMessages:
4
by: bobsawyer | last post by:
I've been building a series of SELECT lists that are populated dynamically using HTTPRequest. Things are going pretty well, and I've got the whole thing working flawlessly in Mozilla/Firebird....
3
by: dumbledad | last post by:
Hi All, I'm confused by how to replace a SELECT statement in a SQL statement with a specific value. The table I'm working on is a list of words (a column called "word") with an index int...
10
by: serge | last post by:
Using "SELECT * " is a bad practice even when using a VIEW instead of a table? I have some stored procedures that are identical with the difference of one statement in the WHERE clause. If I...
1
by: serena.delossantos | last post by:
Trying to insert into a history table. Some columns will come from parameters sent to the store procedure. Other columns will be filled with a separate select statement. I've tried storing the...
9
chunk1978
by: chunk1978 | last post by:
hey everyone, i've been trying to solve this problem for 2 days straight, with no end in sight. i would greatly appreciate anyone's help. EXPLANATION: There are 3 Select Menus. The 1st and...
2
by: naima.mans | last post by:
Hello, i want to select 2 following brothers nodes wich are one under another (one closed to another)... i have done one xslt file... but it's not really good.. for example: the xml file:...
4
by: rn5a | last post by:
A Form has 2 select lists. The 1st one whose size is 5 (meaning 5 options are shown at any given time) allows multiple selection whereas the 2nd one allows only 1 option to be selected at a time. ...
6
by: Apaxe | last post by:
In the database i have a table with this information: key_id =1 key_desc =43+34+22+12 I want sum the values in key_desc. Something like: SELECT key_desc FROM table But the result of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.