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