Click here to Skip to main content
15,902,114 members
Home / Discussions / C#
   

C#

 
GeneralRe: evaluating simple strings as boolean Pin
Nick Parker22-Jul-04 4:13
protectorNick Parker22-Jul-04 4:13 
GeneralCut Image Pin
jzb21-Jul-04 18:50
jzb21-Jul-04 18:50 
GeneralRe: Cut Image Pin
Heath Stewart22-Jul-04 4:10
protectorHeath Stewart22-Jul-04 4:10 
GeneralUser Controls's question Pin
jzb21-Jul-04 18:48
jzb21-Jul-04 18:48 
GeneralRe: User Controls's question Pin
Heath Stewart22-Jul-04 4:03
protectorHeath Stewart22-Jul-04 4:03 
Generalusing different interfaces still works! Pin
ting66821-Jul-04 18:36
ting66821-Jul-04 18:36 
GeneralRe: using different interfaces still works! Pin
Colin Angus Mackay21-Jul-04 23:52
Colin Angus Mackay21-Jul-04 23:52 
GeneralOne major tcp/ip headache Pin
TalkingBabb0t21-Jul-04 17:10
TalkingBabb0t21-Jul-04 17:10 
Hello everyone, I have a problem that I have been banging my head against the wall for the past few days trying to figure out...I am writing a remote assistance service and I want to send a file(a .jpg) using tcp/ip blocking sockets. I have used MANY other peoples source code, but still the file never arrives or I get ugly unhandled exceptions...I finally found one that sort of works...It sends a snapshot of the users screen ONE time, after that the client gives me a "connection reset by software on your remote host", I have included the client and server methods that are running in a seperate continuous thread...your help is MUCH appreciated.

P.S. sorry for the bad formatting.


<---Client source snippet--->
public static void BeginSnapShotSend()
{
ScreenCapture SC = new ScreenCapture();
try
{
// get the remote IP address...
IPHostEntry IPHost = Dns.Resolve("localhost");
IPAddress[] ip = IPHost.AddressList;
int iPortNo = System.Convert.ToInt32(443);
//create the end point
IPEndPoint ipEnd = new IPEndPoint (ip[0],iPortNo);
//connect to the remote host...
PicConnect.Connect ( ipEnd );
nfs = new NetworkStream(PicConnect) ;
}
catch (SocketException SE)
{
System.Windows.Forms.MessageBox.Show(SE.ToString());
return;
}
while (true)
{
SC.CaptureScreenToFile("sc.jpg", ImageFormat.Jpeg);
Thread.Sleep(1000);
try
{
FileStream fin = new FileStream("sc.jpg",FileMode.Open , FileAccess.Read) ;
//Get the Length of the file requested
//and set various variables
long total=fin.Length;
long rdby=0;
int len=0;
byte[] buffed = new byte[4096];
//Open the file requested for download
//One way of transfer over sockets is Using a NetworkStream
//It provides some useful ways to transfer data
byte[] m_sbuf = System.Text.Encoding.UTF8.GetBytes("fsize"+" "+total.ToString());
PicConnect.Send(m_sbuf);
Thread.Sleep(1000);
//lock the Thread here

while(rdby<total&&nfs.canwrite)
{
="" read="" from="" the="" file="" (len="" contains="" number="" of="" bytes="" read)
="" len="fin.Read(buffed,0,buffed.Length)" ;
="" write="" on="" socket
="" nfs.write(buffed,="" 0,="" len);
="" increase="" counter
="" rdby="rdby+len" ;=""
="" }="" display="" a="" message="" showing="" sucessful="" transfer
="" fin.close()="" }
="" catch(exception="" ed)
="" {="" system.windows.forms.messagebox.show("a="" exception="" occured="" in="" transfer"+ed.tostring())="" ;

="" return;
="" }


<---server="" snippet---="">

public void raptwm()
{
IPAddress ipAdress = IPAddress.Any;
IPEndPoint Enp = new IPEndPoint(ipAdress, 443);
Socket ListenTehCliPic = new Socket(AddressFamily.InterNetwork,SocketType.Stream, ProtocolType.Tcp);
ListenTehCliPic.Bind(Enp);
ListenTehCliPic.Listen(0);
Socket WorkWitTehCli = ListenTehCliPic.Accept();
NetworkStream nfs = new NetworkStream(WorkWitTehCli);
ListenTehCliPic.Close();
while (true)
{
bool done =false ;
bool check= false ;
long size=0 ;
long rby=0 ;
while(!done)
{
//declare a buffer
byte[] rce = new byte[2048];
//Recive a Sever Message
waitagain:
int i = WorkWitTehCli.Receive(rce,rce.Length,0) ;
//Convert it to string
string sm = System.Text.Encoding.ASCII.GetString(rce);
if(sm.StartsWith("fsize"))
{
string sizeoffile = sm.Remove(0,6);
//store the File Size
size=Int64.Parse(sizeoffile);
done=true ;
check=true ;
}
else
{
goto waitagain;
}
}
//The File Size has been received the continue
done=false;
//Make a File with the same name as the File that is being downloaded
//Also open a Network Stream to the Server
FileStream fout = new FileStream("sc.jpg", FileMode.OpenOrCreate , FileAccess.Write);
byte[] buffer = new byte[4096] ;
while(!done&&check)
{
try
{
long v=0 ;
//loop till the Full bytes have been read
while(rby<size)
{
="" read="" from="" the="" network="" stream
="" int="" i="nfs.Read(buffer,0,buffer.Length)" ;
="" if(i="">0)
{
//Some checking done to detremine the number of Bytes to be written
if(i>=4096&&(size-rby)>=4096)
{
v=4096 ;
}
else if(i<4096 &&(size-rby)>=4096)
{
v= i;
}
else
{
v=(size-rby) ;
}
//Write the Bytes received to the File
fout.Write(buffer,0,(int)v) ;
rby=rby+v ;

}
}
fout.Close() ;
done=true;
Thread.Sleep(100);
pictureBox1.Image = Image.FromFile("sc.jpg");
}
catch(Exception ed)
{
MessageBox.Show(MW,"A Exception occured in file transfer"+ed.ToString());
}
}
}
}
GeneralRe: One major tcp/ip headache Pin
Heath Stewart22-Jul-04 3:56
protectorHeath Stewart22-Jul-04 3:56 
GeneralRe: One major tcp/ip headache Pin
TalkingBabb0t22-Jul-04 16:19
TalkingBabb0t22-Jul-04 16:19 
GeneralAbout C# Rs232 communication Pin
resocman21-Jul-04 17:09
resocman21-Jul-04 17:09 
GeneralRe: About C# Rs232 communication Pin
Heath Stewart22-Jul-04 3:46
protectorHeath Stewart22-Jul-04 3:46 
GeneralRe: About C# Rs232 communication Pin
resocman22-Jul-04 19:59
resocman22-Jul-04 19:59 
GeneralEvents and Model Logic Pin
Leslie Sanford21-Jul-04 16:44
Leslie Sanford21-Jul-04 16:44 
GeneralRe: Events and Model Logic Pin
Heath Stewart22-Jul-04 3:43
protectorHeath Stewart22-Jul-04 3:43 
Generalpassing a form control to a class Pin
budha_man_9921-Jul-04 11:51
budha_man_9921-Jul-04 11:51 
GeneralRe: passing a form control to a class Pin
Colin Angus Mackay21-Jul-04 14:06
Colin Angus Mackay21-Jul-04 14:06 
GeneralRe: passing a form control to a class Pin
budha_man_9922-Jul-04 4:50
budha_man_9922-Jul-04 4:50 
GeneralRe: passing a form control to a class Pin
Colin Angus Mackay22-Jul-04 5:21
Colin Angus Mackay22-Jul-04 5:21 
GeneralRe: passing a form control to a class Pin
budha_man_9922-Jul-04 5:28
budha_man_9922-Jul-04 5:28 
Generalresize tabPages problem Pin
Andy H21-Jul-04 11:32
Andy H21-Jul-04 11:32 
Generalcolor button example Pin
ddelapasse21-Jul-04 9:20
ddelapasse21-Jul-04 9:20 
GeneralRe: color button example Pin
Gary Thom21-Jul-04 9:58
Gary Thom21-Jul-04 9:58 
GeneralRe: color button example Pin
Anonymous21-Jul-04 10:29
Anonymous21-Jul-04 10:29 
GeneralRe: color button example Pin
Gary Thom22-Jul-04 9:41
Gary Thom22-Jul-04 9:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.