Click here to Skip to main content
15,891,409 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
using (TcpClient client = new TcpClient(ConfigurationManager.AppSettings["TcpIp"], 2000)) //"192.168.3.82", 4973 5000
using (NetworkStream networkStream = client.GetStream())
{
byte[] usernameBytes = Encoding.ASCII.GetBytes(text);
networkStream.Write(usernameBytes, 0, usernameBytes.GetLength(0));
networkStream.Close();
}

This is my code in web application im sending the unicode but the thing is that im not connected to the socket in normal running it will connect in debug mode plz help me for this code asap

What I have tried:

public void OnClientConnect(IAsyncResult asyn)
{
try
{
// Here we complete/end the BeginAccept() asynchronous call
// by calling EndAccept() - which returns the reference to
// a new Socket object
Socket workerSocket = m_mainSocket.EndAccept(asyn);

// Now increment the client count for this client
// in a thread safe manner
Interlocked.Increment(ref m_clientCount);

// Add the workerSocket reference to our ArrayList
GP.m_workerSocketList.Add(workerSocket);

// Send a welcome message to client
string msg = "Welcome client " + m_clientCount + "\n";
SendMsgToClient(msg, m_clientCount);

// OnDataReceived(asyn);

// Update the list box showing the list of clients (thread safe call)
UpdateClientListControl();

// Let the worker Socket do the further processing for the
// just connected client
WaitForData(workerSocket, m_clientCount);

// Since the main Socket is now free, it can go back and wait for
// other clients who are attempting to connect
m_mainSocket.BeginAccept(new AsyncCallback(OnClientConnect), null);

}
catch (ObjectDisposedException)
{
System.Diagnostics.Debugger.Log(0, "1", "\n OnClientConnection: Socket has been closed\n");
}
catch (SocketException se)
{
MessageBox.Show(se.Message);
}
catch (Exception er)
{
MessageBox.Show(er.Message + "\n OnClientConnect function inside TCPServer");
}
}

the above code is in windows application
Posted
Updated 17-Jul-18 22:48pm

1 solution

You need to host the web application in IIS so that it is always available and not just when debugging.
 
Share this answer
 
Comments
Shahbaz435 18-Jul-18 4:53am    
are you sure the code is proper or not
F-ES Sitecore 18-Jul-18 5:13am    
If it works in debug but not "normal" then it's likely to do with how you are executing it rather than the code itself. In debug mode Visual Studio hosts your site itself so it can be connected to. If you want the site available outside of debug mode you need to host the code somewhere else, such as IIS on the local machine.
Shahbaz435 18-Jul-18 5:17am    
i had already done everything but getting the i had host on iis also but not getting the output as expected plz provide me code im new in that
Shahbaz435 18-Jul-18 4:58am    
An established connection was aborted by the software in your host machine

I'm getting the above error

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