Solved

Winsock2 socket() : does protocol = 0 work for SOCK_DGRAM

Posted on 2009-05-05
4
1,095 Views
Last Modified: 2013-11-29
After creating a UDP socket, binding it to a particular IP Address & port, subsequent calls to iocltsocket to determine if any data awaiting receipt constantly indicates 0 ...... although network sniffer indicates messages destined for specified IP Address & port have been transmitted by sender.

However, when creating the UDP socket if specify IPPROTO_UDP in protocol parameter of socket call (instead of zero), messages are subsequently received as expected.

Why ?
Any suggestions gratefully received as need to understand.
OptionValue = SO_SYNCHRONOUS_NONALERT
setsockopt (INVALID_SOCKET, SOL_SOCKET, SO_OPENTYPE, &OptionValue, sizeof(optionvalue))
 
udp_socket = socket (AF_INET, SOCK_DGRAM, 0)
bind (udp_socket, (PSOCKADDR)&local_sin, sin_len)
ioctlsocket (udp_socket, FIONBIO, &argp)       // where argp non-zero
 
.....
 
ioctlsocket (udp_socket, FIONREAD, &argp)
if argp==0 then no data received
NO DATA RECEIVED
----------------------------------------------------------------------------------------------------------------
OptionValue = SO_SYNCHRONOUS_NONALERT
setsockopt (INVALID_SOCKET, SOL_SOCKET, SO_OPENTYPE, &OptionValue, sizeof(optionvalue))
 
udp_socket = socket (AF_INET, SOCK_DGRAM, IPPROTO_UDP)
bind (udp_socket, (PSOCKADDR)&local_sin, sin_len)
ioctlsocket (udp_socket, FIONBIO, &argp)       // where argp non-zero
 
.....
 
ioctlsocket (udp_socket, FIONREAD, &argp)
if argp==0 then no data received
OCCASIONALLY argp NON-ZERO ie: DATA RECEIVED

Open in new window

0
Comment
Question by:chas_newport
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 27

Assisted Solution

by:BigRat
BigRat earned 400 total points
ID: 24312859
The last parameter of the socket() call is the protocol parameter. When you set this to zero the system takes the default protocol for the type of socket being created, which is in this case IPPROTO_IP. Therefore to use the UDP protocol you must set the parameter to IPPROTO_UDP.
0
 

Author Comment

by:chas_newport
ID: 24315500
Many thanks for responding BigRat,

I guess I do not understand the difference between the 2 protocols.

I thought that if a server socket was created with protocol of IPPROTO_IP then any socket with a compatible definition could communicate with this socket.
ie: a 'client' socket created with IPPROTO_UDP protocol could communicate with this 'server' socket defined with a 'universal protocol' of IPPROTO_IP.
Is my understanding correct ?

Perhaps in my example, this is only valid when other options are applied to one or both sockets.

Could you please shed some more light.

Many thanks
0
 
LVL 27

Assisted Solution

by:BigRat
BigRat earned 400 total points
ID: 24316125
The IP protocol is a message system based on IP addresses. It can support several "sub-protocols" based on exactly what is sent in the messages and how subsequent messages are handled. This gives you the possibility of defining your own protocol on top of IP.

UDP is a stateless IP protocol, where as TCP/IP is a state-full protocol. The UDP protocol does NOT guarentee message delivery, whereas TCP/IP establishes a stream and does guarentee delivery (but not necessarily in the correct order!) Both "sit" on top of IP.

If you look at the diagram in http://en.wikipedia.org/wiki/TCP/IP showing the layers from Frame upwards, you'll see that each "protocol" adds a header of it's own. Any good book on TCP/IP or networking protocols will give you the messy details you don't need to know. That's the good thing about this layered system, originally defined as the ISO, and developed in the 80's for the Arpanet.
0
 

Accepted Solution

by:
chas_newport earned 0 total points
ID: 24539322
Many thanks for your assistance BigRat,

The issue has finally been resolved ...... and wasn't related to the protocol but a peculiarity with the equipment processing.

Thanks again
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
This is the first one of a series of articles I’ll be writing to address technical issues that are always referred to as network problems. The network boundaries have changed, therefore having an understanding of how each piece in the network  puzzl…
After creating this article (http://www.experts-exchange.com/articles/23699/Setup-Mikrotik-routers-with-OSPF.html), I decided to make a video (no audio) to show you how to configure the routers and run some trace routes and pings between the 7 sites…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question