Click to See Complete Forum and Search --> : tcp adn udp on the same port
drewdaman
December 8th, 2004, 12:54 PM
i have a pretty basic question for you guys:
i have a tcp and udp socket. i'm trying to do everything twice.. once with tcp and once with udp so the user can choose which to use.
would there be problems if i bind my tcp socket and udp socket to the same port? its worked so far.. but i'm having some problems now and i'm wondering if that could be the cause.
a little confused,
thanks!
drew.
ps. i dont' close either of the sockets now. i used to close the tcp socket before using the udp one. could this be my problem?
Mathew Joy
December 9th, 2004, 02:47 AM
Your question has been discussed in another thread of yours (In-fact it has been left dangling). It is possible and AFAIK you shouldn't be getting any problems just because of this. Now what is the problem?
drewdaman
December 9th, 2004, 10:21 AM
thanks for replying matthew. i'm apologize if i posted this twice, although i don't remember having posted this question before.
i have found the problem after doing A LOT of debugging! and it wasn't related to this. i just wanted to make sure that this wasn't causing the problem.
Mathew Joy
December 9th, 2004, 01:21 PM
thanks for replying matthew. i'm apologize if i posted this twice, although i don't remember having posted this question before.I find it odd that you don't remember a thread that you posted a few days back. I'm posting it for you http://www.codeguru.com/forum/showthread.php?t=319662
i have found the problem after doing A LOT of debugging! and it wasn't related to this. i just wanted to make sure that this wasn't causing the problem.You still haven't mentioned the problem.
drewdaman
December 10th, 2004, 12:01 PM
well.. that question was different. this one is about ports. that one was about binding two sockets to the same sockaddr_in. here i was just wondering if there would be a problem listening (well.. not listening in the "listen()" sense.. just watching for incoming data) on the same port using two different sockets using two different protocols. before i started changing the code, i closed teh tcp connection before starting the udp transfer. now i want both active at the same time.
the problem was that i couldn't send/receive. it was because i had closed the socket.. i thought i had deleted that line.. in fact, i was so sure that i had deleted the part that closes the socket, that i didn't even think it was necessary to check :( i'm an idiot! lol... never take anything for granted while coding!!!!!! well.. it turned out that the close line was there...
thanks for the interest tho!
drew.
ps.. what does AFAIK mean?
Mathew Joy
December 11th, 2004, 01:53 AM
well.. that question was different. this one is about ports. that one was about binding two sockets to the same sockaddr_in.So, in other words you are saying it is possible to bind two sockets to the same sockaddr_in yet different ports.
If I haven't missed any thing significant from your posts, both are the same. Is it possible to bind two sockets to the same port provided the protocols are different?
In fact the structure SOCKADDR is there in wsock 2 only for the compatibility with wsock 1.
In Windows Sockets 2, the name parameter is not strictly interpreted as a pointer to a SOCKADDR structure. It is cast this way for Windows Sockets 1.1 compatibility.So sockets are said to be bound to a name not sockaddr to be precise. About name A name consists of three parts when using the Internet address family:
The address family.
A host address.
A port number that identifies the application.
At the time of socket creation The Windows Sockets socket function creates a socket that is bound to a specific service provider....in other words bound to a protocol(to make explanation simpler). Now when we call bind When a socket is created with a call to the socket function, it exists in a name space (address family), but it has no name assigned to it. Use the bind function to establish the local association of the socket by assigning a local name to an unnamed socket.
Further on bind it is said Only one usage of each socket address (protocol/IP address/port) is normally permitted.Note it is said one usage of each socket address. In other words if all the entries of the tuple is same for 2 socket address you are using the same socket address, which is not normally permitted. (Also note the usage of the word normally). If you change one of the entry of the tuple you get a different socket address. Now I think this answers your question.
Since I haven't used it or read this kind of usage in other discussions, I do not know the behavior which is why I said in both the threads to let us know if you get any problems because of this.
drewdaman
December 13th, 2004, 04:43 PM
So, in other words you are saying it is possible to bind two sockets to the same sockaddr_in yet different ports.
If I haven't missed any thing significant from your posts, both are the same. Is it possible to bind two sockets to the same port provided the protocols are different?
yes i am saying that. i assume it will be ok even if the protocol is the same. what i was forgetting (i was extremely frustrated at the time!) was that you actually tell the program what socket to receive on! at the time i posted this, i hadn't realized that a socket was being closed and that was the reason i couldn't send/receive on it!
Since I haven't used it or read this kind of usage in other discussions, I do not know the behavior which is why I said in both the threads to let us know if you get any problems because of this.
the problems i got were due to other small errors i had in my code as i mentioned in my previous post. they were just silly mistakes (although i was quite baffled by them for a while!), which is why i didn't mention them here.
thanks again for replying and the interest you've taken in this post!
Mathew Joy
December 14th, 2004, 12:51 PM
i assume it will be ok even if the protocol is the same.Which means you have to go thru my post once again.
thanks again for replying and the interest you've taken in this post!You are welcome.
I intended to post this in your other thread, especially since there was a incorrect post as your answer. But since you didn't reply, I thought why bother if the OP is not interested.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.