Chat application in wpf using TCp/IP
-
You having an issue doing it or just asking if anyone here has one they are willing to give? WPF does not really stop you form using raw sockets unless you are doing an XBAP, app and then you may need to adjust some security to allow it to work. Do you have a specific aversion to using WCF or do you have a hard requirement that you must use raw sockets.
-
You having an issue doing it or just asking if anyone here has one they are willing to give? WPF does not really stop you form using raw sockets unless you are doing an XBAP, app and then you may need to adjust some security to allow it to work. Do you have a specific aversion to using WCF or do you have a hard requirement that you must use raw sockets.
Listen PartSocket newsock = new Socket( AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp ); IPEndPoint iep = new IPEndPoint( IPAddress.Any, 2091 ); newsock.Bind( iep ); newsock.Listen( 5 ); newsock.BeginAccept( new AsyncCallback( AcceptConn ), newsock ); void AcceptConn( IAsyncResult iar ) { Socket oldserver = ( Socket )iar.AsyncState; client = oldserver.EndAccept( iar ); Thread receiver = new Thread( new ThreadStart( ReceiveData ) ); receiver.Start(); } void ReceiveData() { int recv; string stringData; while( true ) { recv = client.Receive( data ); stringData = Encoding.ASCII.GetString( data, 0, recv ); if( stringData == "bye" ) break; } stringData = "bye"; byte[] message = Encoding.ASCII.GetBytes( stringData ); client.Send( message ); client.Close(); return; } Connection client = new Socket( AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp ); IPEndPoint iep = new IPEndPoint( IPAddress.Parse( "127.10.27.61" ), 2091 ); client.BeginConnect( iep, new AsyncCallback( Connected ), client ); void Connected( IAsyncResult iar ) { client.EndConnect( iar ); Thread receiver = new Thread( new ThreadStart( ReceiveData ) ); receiver.Start(); } My code is like thisduring the connection part error happends,May be due to 2 threads,how can i solve the same