I am developing a LAN messenger in c# using sockets, i want to use XML for entire communication, can you people help me? or give me some link or code snippet?
any help will be appreciated
thanks in advance

Recommended Answers

All 6 Replies

You say you want to use XML for communication? In what sense? What you send over the socket needs to be converted into bytes. So build your XML in memory, then convert that into a byte array and send it over your socket and rebuild it at the other end.

There is no function to send XML over a socket.

An alternative is to use WCF. Lots of information about WCF can be found in the MSDN

@ Ketsuekiame
the requirement given to me is:-

You're required to implement a LAN Messenger software:-


Feature List
- Chat with One or Multiple Friends at a time.
- Notification Icon of application in System Tray.
- Popup window when a friend signs in.

Note
- Entire communication shall be done using XML.
- Each message will be verified using DTD.

To transmit the data over the network, you still need to break it down into bytes. But the message you send can be in XML.

I imagine you will be running a server, which communicates with all the clients? If not, that's going to be rather difficult to implement ^^

@ Ketsuekiame
yes you are right brother, server will communicate with all clients, and the message will be broken in bytes, but i want to use XML to transmit these bytes to clients. :-)

Perhaps something like this can help. Says something about DTD also. Or are you not alowed to use such features?

Well if you need to use XML as your "message" then how about something like this as your markup...

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<ClientMessage>
    <SourceClientId>SomeIdHere</SourceClientId>
    <ClientCommand>Message</ClientCommand>
    <TargetClients>
        <Client>TargetClientOne</Client>
        <Client>TargetClientTwo</Client>
    </TargetClients>
    <Data>Whatever the message is here</Data>
</ClientMessage>

Obviously you would need a DTD that also matches this and the DTD should cover a message that is either from a client or a server. This is just to give you an idea.

Once you have the XML, you can serialise it into a byte stream fairly easily. Look into the BinaryFormatter

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.