Error when transmitting file through TCP

Status
Not open for further replies.

testing test

Member level 3
Joined
Mar 3, 2010
Messages
65
Helped
5
Reputation
10
Reaction score
3
Trophy points
1,288
Visit site
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: 100
  • ReceiveFiles.zip
    33.5 KB · Views: 90
  • error_message.png
    18.6 KB · Views: 121

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:


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

Cookies are required to use this site. You must accept them to continue using the site. Learn more…