Click here to Skip to main content
15,907,497 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi all,
I have developed a application that is used for file transfer using TCP/IP Communication.Problem i am facing is 'sometimes' it is throwing exception as "No Connection could be made bacause the target machine actively refused it" at the below line
//if yes then send a token to the sender to send a file.
                 receiverSock.Connect(strSenderIP, intPort);//put sender IP

Kindly help me in resolving the mentioned issue.
ashok rathod 26-Jun-14 6:39am    
As per your Error Messsage, It is Clearly Indicates that sometimes your machine disconnects from server machine due to some issue. Please verify and check that you have consistent communication possible on tcp/ip port provided whenver u gets that error try to telnet particular IP address/port if it succeed then there might be issue with your code.
Sprint89 26-Jun-14 9:25am    
Try a netstat -a to see if anything else is blocking that port
Rahul VB 1-Jul-14 2:51am    
Try to ping the server from the client and vice versa. Verify the port number too.

One more thing you need to be completely sure that you want to connect to or receive from a socket. So for that use socket.Accept method. Hope fully that should help.

In my last company i used to work on PLC devices. The PLC device which i was using, was configured to behaive as a client. So my application became the server. Which means i needed to accept the socket connection. But i was doing vice versa and hence it said "could not connect to the device because the machine is actively refusing it."

After finding this out, i accepted the connection from the slave device after which i was able to do other operations.

So you need to find out a few things:
1)Is the device with which you want to communicate a client/server?
2)Are you specifying the correct port number and the IP address?
3)Is firewall blocking your port?

i dont think there can be any thing else other than that. Please do try it and keep posting.

Thanks and Regards,

1 solution

Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900