0

If I want to have a datagram socket, what do I have to change here ? It's a stream socket right now.
Just change it where it creates the socket ?

sockfd = socket(PF_INET,SOCK_STREAM,0);

2
Contributors
4
Replies
20
Views
2 Years
Discussion Span
Last Post by Hiroshe
0

ops. double. Sorry.

Edited by XodoX

0

It's a tcp server.

sockfd = socket(PF_INET,SOCK_DGRAM,0);
    printf("Socket: %d created. \n", sockfd); 

So once you change that, everything else seems to stay the same..like the binding ? I think that's it, because that's how you define it.

Edited by XodoX

0

Read the first answer more carefully. It's not quite that simple.

I'll try to explain whats going on in the background, and that might shed some light on why it's not that simple. A datagram has a header and a payload. The header needs to contain information on where the packet is going. This is so it can be easily be routed through complicated networks - for example, to send something over the internet, you need a destination ip address. This is not the case for unix stream sockets, which are more like names pipes.

In the olden days, we used switches to make networks. There kind of like routers - but with one big difference. Each packet is sent to each computer! So, a server needed to be aware of what it's address was so it could ignore packets that's not addressed to it.

It's a tcp server.

Then why are you using datagrams? Datagrams are used in UDP/IP. TCP/IP uses an enturely different system. Unless your trying to say your manually implementing TCP over UDP/Ip. In which case, you're doing something very stange indeed.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.