0
votes

Can I send and receive UDP datagrams on same socket,I am using for TCP communication.There exist multimedia communication in my application for which I have to use UDP for communication.If i create a new socket it threw an exception for properties of LingerState and NoDelay.When I Assigns the Old Socket Instance to other Socket variable it doesn't Allow me to change the properties as most of the properties are read Only.I have to Send data in the TCP connected Area.

*Code *

Socket SendingSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); IPEndPoint Endp = new IPEndPoint(IPAddress.Parse("192.168.3.233"), port);

SendingSocket.Bind(Endp);

while (SendingSocket.Connected)
{ string Message = "Testing Message Sending Over UDP"; ASCIIEncoding Encode = new ASCIIEncoding(); byte[] MessageBytes = Encode.GetBytes(Message); SendingSocket.SendTo(MessageBytes, 0, MessageBytes.Length, SocketFlags.None, Endp); }'

2
TCP and UDP work completely differently. TCP maintains a constant connection between client/server until it's closed/dropped. UDP doesn't. Any software that I've seen needing both have two sockets in use, one for TCP and the other for UDP.GeoffM
I am Just asking that it is the requirement of the application.That I have communicate separablySamie

2 Answers

1
votes

Hard to tell from that code fragment but possibly you do not need the SendingSocket.Bind(Endp) since your SendingSocket.SendTo also includes the IP end point. Also try simply

SendingSocket.SendTo(MessageBytes, Endp);
0
votes

No. You can not use the same socket for both TCP and UDP. A socket is bound to only one protocol.