My code is successfully sending and processing ing images using sockets .... but problem is that I want to send messages along images .... ie if client sends all images from a defined location... then client must send a message to tell server .... that now its server turn to send image... if I merge messsage along byte data of images then... on Loading ing end only image file is created but no previou... means images are not displayed ....
Code is placed below...
Public void receiveimage ()
{
Try
{
Sock. Listen (100 );
Socket clientsock = sock. Accept ();
Byte [] clientdata = new byte [1024*5000];
Int receivedbyteslen = clientsock. Receive (clientdata );
If (receivedbyteslen = 19)
{
String message = encoding. ASCII. getstring (clientdata, 0, 19 );
If (Message = "server_img_complete ")
{
Thread. Sleep (6000 );
Sendimage objfrm = new sendimage ();
Objfrm. getpatientdocuments ();
}
}
Else
{
Receivedpath = system. configuration. configurationsettings. receivettings ["receivedpath"]. tostring ();
Int filenamelen = bitconverter. toint32 (clientdata, 0 );
String filename = encoding. ASCII. getstring (clientdata, 4, filenamelen );
Binarywriter bwrite = new binarywriter (file. Open (receivedpath + "/" + filename, filemode. append ));;
Bwrite. Write (clientdata, 4 + filenamelen, receivedbyteslen-4-filenamelen );
DB. openconnection ();
String start_from = dB. getfielddescription ("ss_emr_image_sync_time_log", "Top 1 (date_to) as field_date", "acknowledged = 1 order by sr desc ");
Bwrite. Close ();
Clientsock. Close ();
}
Receiveimage ();
}
</Code>
Code for client application:
Class ftclientcode
{
Public static void sendfile (string filename)
{
Try
{
IPaddress [] IPaddress = DNS. gethostaddresses ("localhost ");
Ipendpoint ipend = new ipendpoint (IPaddress [0], 5656 );
Socket clientsock = new socket (addressfamily. InterNetwork, sockettype. Stream, protocoltype. IP );
String filepath = "";
Filename = filename. Replace ("\\","/");
While (filename. indexof ("/")>-1)
{
Filepath + = filename. substring (0, filename. indexof ("/") + 1 );
Filename = filename. substring (filename. indexof ("/") + 1 );
}
Byte [] filenamebyte = encoding. ASCII. getbytes (filename );
If (filenamebyte. length> 850*1024)
{
Curmsg = "file size is more than 850kb, please try with small file .";
Return;
}
// Byte [] clientdata = new byte [12 + filenamebyte. Length + filedata. Length];
Byte [] filenamelen = bitconverter. getbytes (filenamebyte. Length );
Byte [] Message = encoding. ASCII. getbytes ("image_ OK ");
Filenamelen. copyto (clientdata, 0 );
Filenamebyte. copyto (clientdata, 4 );
Filedata. copyto (clientdata, 4 + filenamebyte. Length );
Message. copyto (clientdata, filenamebyte. Length + filedata. Length );}
}
Clientsock. Connect (ipend );
Clientsock. Send (clientdata );
Clientsock. Close ();
awaitng for ur kind response.
thanks