Language: ChineseGermanSpanishFrenchDutchItalianRussian
123 Flash Chat Forums

Go Back   TOPCMM Community > 123 Flash Chat Server Software > 123 Flash Chat Support

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-05-2011, 03:34 PM
Junior Member
 
Join Date: Mar 2011
Posts: 3
Default Add room api in C#

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
Reply With Quote
  #2 (permalink)  
Old 08-09-2011, 06:12 PM
Junior Member
 
Join Date: Mar 2011
Posts: 3
Default

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!
Reply With Quote
  #3 (permalink)  
Old 08-10-2011, 09:46 AM
Member
 
Join Date: Jan 2005
Posts: 96
Send a message via MSN to Cloudy
Default

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;
}
}
Reply With Quote
  #4 (permalink)  
Old 01-09-2012, 11:31 PM
Junior Member
 
Join Date: Mar 2011
Posts: 3
Default

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!
Reply With Quote
  #5 (permalink)  
Old 01-10-2012, 12:52 AM
Member
 
Join Date: Jan 2005
Posts: 96
Send a message via MSN to Cloudy
Default

The port should be 51127 by default, 51127 is for server api and 35555 is for data api.
Reply With Quote
Reply

Was this information helpful?    Yes No



Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 01:48 PM.


Powered by vBulletin® Version 3.7.1
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.