ItsMods

Full Version: C#/C++ I Need help!
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi guys, i have small problem: my cpp program doesnt not work (dont play sound)
C++ Code
  1. #include <Windows.h>
  2. #include <iostream>
  3. #include <MMsystem.h>
  4. #pragma comment(lib,"winmm.lib")
  5. #pragma comment(lib,"dsound.lib")
  6. using namespace std;
  7. int main()
  8. {
  9. int a = 5;
  10. int b;
  11. cin >>b;
  12. if(b<= a)
  13. {
  14.  
  15. PlaySound(TEXT("windowsxp.wav"),NULL,SND_SYNC);
  16.  
  17. }
  18. system("pause");
  19. return 0;
  20. }
It's the most easiest task ever.
Simple networking. I can give c++/c example, but I forgot this stuff in c#. It's P2P ( peer to peer ) connection.
I can give you a tip: use tcp.
(12-14-2014, 21:11)Nekochan Wrote: [ -> ]It's the most easiest task ever.
Simple networking. I can give c++/c example, but I forgot this stuff in c#. It's P2P ( peer to peer ) connection.
I can give you a tip: use tcp.
Example please
Well, as I said I don't remember some stuff from C#, but here you go, pseudocode.
Code:
// Create a tcp stuff.
int mPort = 1082; // Taking lower than 1024 will give you an errors, these are system-precached.
TcpListener mServerSocket = new TcpListener( mPort );
TcpClient mClientSocket = default( TcpClient );
mServerSocket .Start(); // Start server.

Console.WriteLine("Server started.");
while( true ) {
                mClientSocket = mServerSocket.AcceptTcpClient(); // Wait for connections.

                byte[] recvBytes = new byte[16384];
                string clientData = null;

                NetworkStream networkStream = mClientSocket.GetStream(); // Read client data.
                networkStream.Read( recvBytes , 0, (int)mClientSocket.ReceiveBufferSize );

                clientData = System.Text.Encoding.ASCII.GetString( recvBytes ); // Create UTF8/ASCII string.

                Console.WriteLine( "Someone joined." );

                ParseCommands( clientData ); // Here you parse your commands from client.
}

For client, use the same method, but remove 'start' and use 'connect'
Code:
mClientSocket.Connect(" *IPADDRESS* ",  1082 );

and then use 'Send' with commands you wish.  eg: "Send("playsound Soundname")". and parse it in ParseCommands function. ( Split string ).
(12-14-2014, 21:57)Nekochan Wrote: [ -> ]Well, as I said I don't remember some stuff from C#, but here you go, pseudocode.
Code:
// Create a tcp stuff.
int mPort = 1082; // Taking lower than 1024 will give you an errors, these are system-precached.
TcpListener mServerSocket = new TcpListener( mPort );
TcpClient mClientSocket = default( TcpClient );
mServerSocket .Start(); // Start server.

Console.WriteLine("Server started.");
while( true ) {
                mClientSocket = mServerSocket.AcceptTcpClient(); // Wait for connections.

                byte[] recvBytes = new byte[16384];
                string clientData = null;

                NetworkStream networkStream = mClientSocket.GetStream(); // Read client data.
                networkStream.Read( recvBytes , 0, (int)mClientSocket.ReceiveBufferSize );

                clientData = System.Text.Encoding.ASCII.GetString( recvBytes ); // Create UTF8/ASCII string.

                Console.WriteLine( "Someone joined." );

                ParseCommands( clientData ); // Here you parse your commands from client.
}

For client, use the same method, but remove 'start' and use 'connect'
Code:
mClientSocket.Connect(" *IPADDRESS* ",  1082 );

and then use 'Send' with commands you wish.  eg: "Send("playsound Soundname")". and parse it in ParseCommands function. ( Split string ).

Thanks you Heart , I understand C++ code :-) .
You can help me?
How me make endless loop on C#?
I am need in check some events in every 10 minute?
dont click on button/ ets events