|
|||
|
I am trying to figure out how to use the api from a c# app. I was able to find a php example but can't get it to work from c#. Here is the code I have so far:
string str = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><Command group=\"default\" api_pwd=\"3874-3459-9293-2194\" type=\"add_room\" name=\"lanerrrrrflashchat\" owner=\"admin\" desc=\"flashchattest\" max=\"199\" />"; Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); socket.Connect("localhost", 35555); socket.Send(Encoding.UTF8.GetBytes(str)); It executes without errors, but doesn't actually create the room and I'm not sure how to debug or retrieve a response from the flashchat server? Thanks, Lane |
|
|||
|
Can anyone provide any help on this at all? I would think FlashChat would at least have an example of how to use their API in .Net, not just php? This is especially the case since the API doesn't use common web services that would be easy to integrate with regardless of technology.
Please Help! |
|
|||
|
Here's is a quick function for sending api command to 123flashchat server in c#,change init_host and init_port in the code.
private int socketProcess(string sendCommand) { Byte[] buffer = new Byte[1024]; IPAddress ip = IPAddress.Parse(init_host); IPEndPoint ipe = new IPEndPoint(ip, init_port); Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); try { socket.Connect(ipe); byte[] bs = Encoding.ASCII.GetBytes(sendCommand); byte[] temp = new byte[bs.Length + 1]; Array.Copy(bs, temp, bs.Length); temp[temp.Length - 1] = 0; socket.Send(temp, temp.Length, 0); int byteCount = socket.Receive(buffer, 1024, SocketFlags.None); if (byteCount > 0) { string getXML = Encoding.UTF8.GetString(buffer); return parseXML(getXML); } else { return UNKNOWN_ERROR; } } catch (SocketException e) { Response.Write(e.Message); return UNKNOWN_ERROR; } } |
|
|||
|
Hi Cloudy - thanks much for sending this, but I can't get it working. the bytecount always results in zero.
I have set the correct values in the server.xml I think: <server-api enable="On"> <!-- auth-password Commands will be declined by the chat server unless it comes with the right password. --> <auth-password>3874-3459-9293-2194</auth-password> <!-- allow-access-from-ip Only command from this IP is legitimate to access. If set to "*", then commands from all IP address are valid and that will be insecure to the chat server. --> <allow-access-from> <ip>*</ip> </allow-access-from> </server-api> And here is my code: [TestMethod] public void socketProcessSend() { //string str = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><Command group=\"default\" api_pwd=\"3874-3459-9293-2194\" type=\"add_room\" name=\"lanerrrrrflashchat\" owner=\"admin\" desc=\"flashchattest\" max=\"77\" />"; //string str = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><Command group=\" string sendCommand = "<connection number >|<logon user number>|<room numbers>"; string init_host = "192.168.1.151"; int init_port = 35555; Byte[] buffer = new Byte[1024]; IPAddress ip = IPAddress.Parse(init_host); IPEndPoint ipe = new IPEndPoint(ip, init_port); Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp); int byteCount = 0; try { socket.Connect(ipe); byte[] bs = Encoding.ASCII.GetBytes(sendCommand); byte[] temp = new byte[bs.Length + 1]; Array.Copy(bs, temp, bs.Length); temp[temp.Length - 1] = 0; socket.Send(temp, temp.Length, 0); byteCount = socket.Receive(buffer, 1024, SocketFlags.None); if (byteCount > 0) { string getXML = Encoding.UTF8.GetString(buffer); //return parseXML(getXML); } else { //return UNKNOWN_ERROR; } } catch (SocketException e) { //Response.Write(e.Message); //return "UNKNOWN_ERROR"; } Assert.AreNotEqual(0, byteCount); } any ideas? thanks! |
![]() |
Was this information helpful? Yes No
| Thread Tools | |
| Display Modes | |
|
|