Simple implementation of XMPP-based server-side file transfer yesterday we talked about the principle of client-side implementation of user-side message sending. Today we will continue to learn about XMPP-based file transmission, first, let's assume that the user has logged on. Here we assume that clinet send sends to the clinet receive file, and here records the XML Stream records for sending and receiving clinet send.
1. Send a request to send a file to clinet test, and send the file size and file name Send: < IQ Xmlns = "Jabber: client" ID = "Agsxmpp_6" To = "Receive @ localhost /" Type = "Set" > < Si Xmlns = "Http://jabber.org/protocol/si" Profile = "Http://jabber.org/protocol/si/profile/file-transfer" ID = "B3b5f49c-8a94-49e2-908a-3de694b98af0" > < File Xmlns = "Http://jabber.org/protocol/si/profile/file-transfer" Name = "Miniclient.exe. config" Size = "382" > < Range /> </ File > < Feature Xmlns = "Http://jabber.org/protocol/feature-neg" > < X Xmlns = "Jabber: X: Data" Type = "Form" > < Field Type = "List-single" VaR = "Stream-method" > < Option > < Value > Http://jabber.org/protocol/byReceive reams </ Value > </ Option > </ Field > </ X > </ Feature > </ Si > </ IQ >
2. After receiving the send request, receive sends the response stream. Recv: < IQ Xmlns = "Jabber: client" To = "Send @ localhost" Type = "Result" ID = "Agsxmpp_6" > < Si Xmlns = "Http://jabber.org/protocol/si" ID = "B3b5f49c-8a94-49e2-908a-3de694b98af0" > < Feature Xmlns = "Http://jabber.org/protocol/feature-neg" > < X Xmlns = "Jabber: X: Data" Type = "Submit" > < Field VaR = "Stream-method" > < Value > Http://jabber.org/protocol/byReceive reams </ Value > </ Field > </ X > </ Feature > </ Si > </ IQ >
3. After receiving the response that receive is willing to receive, send the following XML Stream Send: < IQ Xmlns = "Jabber: client" ID = "Agsxmpp_7" To = "Receive @ localhost" Type = "Set" > < Query Xmlns = "Http://jabber.org/protocol/bySendreams" Sid = "71f1b875-4d84-429c-b39d-7dabcd400f3d" > < Streamhost Jid = "Send @ localhost/miniclient" Host = "Localhost" Port = "1000" /> < Streamhost Jid = "Proxy.ag-software.de" Host = "Proxy.ag-software.de" Port = "7777" /> </ Query > </ IQ >
Note that if proxy settings are used here, the client that comes with agsxmpp uses the proxy to transmit data. Therefore, you must modify the client so that it supports sending files in the LAN.
Next, let's take a look at how the server routes messages?
From the XML Stream sent above, we can see that in fact, all files transmitted by users are sent in IQ section. We must route the IQ section to find the corresponding receiver, therefore, we need to add the following in the xmppserverconnection class:Code:
Private Void Processiq (IQ)
{
// Transfer File Processing
If (IQ. Query = Null )
{
If (IQ. Type = Iqtype. Result)
This . Send (IQ );
Processoobiq (IQ );
}
Else
If (IQ. query. GetType () = Typeof (Auth ))
{
Auth auth = IQ. Query As Auth;
This . Username = Auth. username. tostring ();
Switch (IQ. type)
{
Case Iqtype. Get :
IQ. switchdirection ();
IQ. Type = Iqtype. result;
Auth. addchild ( New Element ( " Password " ));
Auth. addchild ( New Element ( " Digest " ));
Send (IQ );
Break ;
Case Iqtype. Set :
// Here we shoshould verify the authentication credentials
If (Accountbus. checklogin (Auth. username, Auth. Digest, This . Sessionid ))
{
IQ. switchdirection ();
IQ. Type = Iqtype. result;
IQ. Query = Null ;
Send (IQ );
Console. writeline (Auth. Username + " Logged On " + " Logon Time: " + System. datetime. Now. tostring ());
}
Else
{
// IQ. switchdirection ();
IQ. Type = Iqtype. error;
IQ. Query = Null ;
Send (IQ );
}
Break ;
}
}
Else If (IQ. query. GetType () = Typeof (Roster ))
{
Processrosteriq (IQ );
} // Use a proxy to transfer files
Else If (IQ. query. firstchild ! = Null )
{
// IQ. switchdirection ();
// // IQ. type = iqtype. result;
// // Send (IQ );
// IQ. type = iqtype. Set;
// This. Send (IQ );
Processoobiq (IQ );
}
}
Transfer File Path: