Search Results

Search found 3 results on 1 pages for 'asen'.

Page 1/1 | 1 

  • c# How to get string from byte?

    - by Kade
    I have a form-console application which does a TCP socket connections for send and receive. I need help getting the following response to STRING. The following code does write the RESPONSE to the console, but i also want to byte[] b = new byte[100]; int k = s.Receive(b); Console.WriteLine("Recieved..."); for (int i = 0; i < k; i++) Console.Write(Convert.ToChar(b[i])); ASCIIEncoding asen = new ASCIIEncoding(); s.Send(asen.GetBytes("RECEIVED :")); i want to get something like String GETSTRING; byte[] b = new byte[100]; int k = s.Receive(b); Console.WriteLine("Recieved..."); for (int i = 0; i < k; i++) Console.Write(Convert.ToChar(b[i])); GETSTRING = *WHATEVER RESPONSE RECEIVED ABOVE* ASCIIEncoding asen = new ASCIIEncoding(); s.Send(asen.GetBytes("RECEIVED :"));

    Read the article

  • c# send recive object over network?

    - by Data-Base
    Hello, I'm working on a server/client project the client will be asking the server for info and the server will send them back to the client the info may be string,number, array, list, arraylist or any other object I found allot of examples but I faced issues!!!! the solution I found so far is to serialize the object (data) and send it then de-serialize it to process here is the server code public void RunServer(string SrvIP,int SrvPort) { try { var ipAd = IPAddress.Parse(SrvIP); /* Initializes the Listener */ if (ipAd != null) { var myList = new TcpListener(ipAd, SrvPort); /* Start Listeneting at the specified port */ myList.Start(); Console.WriteLine("The server is running at port "+SrvPort+"..."); Console.WriteLine("The local End point is :" + myList.LocalEndpoint); Console.WriteLine("Waiting for a connection....."); while (true) { Socket s = myList.AcceptSocket(); Console.WriteLine("Connection accepted from " + s.RemoteEndPoint); var b = new byte[100]; int k = s.Receive(b); Console.WriteLine("Recieved..."); for (int i = 0; i < k; i++) Console.Write(Convert.ToChar(b[i])); string cmd = Encoding.ASCII.GetString(b); if (cmd.Contains("CLOSE-CONNECTION")) break; var asen = new ASCIIEncoding(); // sending text s.Send(asen.GetBytes("The string was received by the server.")); // the line bove to be modified to send serialized object? Console.WriteLine("\nSent Acknowledgement"); s.Close(); Console.ReadLine(); } /* clean up */ myList.Stop(); } } catch (Exception e) { Console.WriteLine("Error..... " + e.StackTrace); } } here is the client code that should return an object public object runClient(string SrvIP, int SrvPort) { object obj = null; try { var tcpclnt = new TcpClient(); Console.WriteLine("Connecting....."); tcpclnt.Connect(SrvIP, SrvPort); // use the ipaddress as in the server program Console.WriteLine("Connected"); Console.Write("Enter the string to be transmitted : "); var str = Console.ReadLine(); Stream stm = tcpclnt.GetStream(); var asen = new ASCIIEncoding(); if (str != null) { var ba = asen.GetBytes(str); Console.WriteLine("Transmitting....."); stm.Write(ba, 0, ba.Length); } var bb = new byte[2000]; var k = stm.Read(bb, 0, bb.Length); string data = null; for (var i = 0; i < k; i++) Console.Write(Convert.ToChar(bb[i])); //convert to object code ?????? Console.ReadLine(); tcpclnt.Close(); } catch (Exception e) { Console.WriteLine("Error..... " + e.StackTrace); } return obj; } I need to know a good serialize/serialize and how to integrate it into the solution above :-( I would be really thankful for any help cheers

    Read the article

  • Is it possible to change 2-3 times f->SetSensor() ?

    - by Asen
    Hello there ! i use cocos2d-iphone-0.99.2 and integrated in it box2d. i have 2 kind of sprites with tags 1 and 2. Also i created bodies and shape definitions for them. what i'm trying to do is to make sprite1 kinds to act as solid or act as not solid when sprite2 colides with them. i tried this code : for(b2Body *b = _world->GetBodyList(); b; b=b->GetNext()) { if (b-GetUserData() != NULL) { CCSprite *sprite = (CCSprite )b-GetUserData(); if (sprite.tag == 1) { b2Fixture f = b-GetFixtureList(); f-SetSensor(solid); } } } Where solid is bool. The first time when i change fixture to sensor everything is just fine but when i try to revert and change again to solid my app crashes with the following error : Assertion failed: (manifold-pointCount 0), function b2ContactSolver, file /Documents/myapp/libs/Box2D/Dynamics/Contacts/b2ContactSolver.cpp, line 58. Is it possible somehow to change fixture-SetSensor several times and if so ... how ? Any help is highly appreciated.

    Read the article

1