Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Error when transmitting file through TCP

Status
Not open for further replies.

testing test

Member level 3
Member level 3
Joined
Mar 3, 2010
Messages
65
Helped
5
Reputation
10
Reaction score
3
Trophy points
1,288
Activity points
1,656
Hi,

I have attached the zip files for the sender side and the receiver side. I am running these projects in Visual Studio (Visual C#). The purpose is to send an audio file from the sender to a receiver.

It is giving me some error when I run the project. The error message is also attached. Please let me know how to fix this error.

Thank you.
 

Attachments

  • SendFiles.zip
    21.4 KB · Views: 98
  • ReceiveFiles.zip
    33.5 KB · Views: 89
  • error_message.png
    error_message.png
    18.6 KB · Views: 117

You allocate client and netstream inside a try...catch block, but then close them inside the finally {} block. So you are not guaranteed these attributes are not null in case of error. Do instead:

finally
{
if (netstream)
netstream.Close();
if (client)
client.Close();
}
 

Here is another scenario I am having now. I have started the receiver on one machine and then started the sender.

The port number I used is 29250.

When I select a file and send it to the receiver, a dialog box at the receiver pops up asking me to accept the incoming file.

When I click Yes to accept the incoming file, the receiver side shows the following error:

A first chance exception of type 'System.Threading.ThreadStateException' occurred in System.Windows.Forms.dll
Current thread must be set to single thread apartment (STA) mode before OLE calls can be made. Ensure that your Main function has STAThreadAttribute marked on it. This exception is only raised if a debugger is attached to the process.

The owner of this code told me to this:

It looks you need to set the thread which is used to receive to STA

But I am not sure how to do this. Can anyone please let me know?

Thank you.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top