Hey, now Im trying to send packets via c# console app, but it wont work. I can receive all packages but cant send them.
Here is my code to receive packages:
Code:
using System.Net.Sockets;
using System.Text;
namespace Client
{
class Program
{
const int PORT_NO = 50659;
const string SERVER_IP = "127.0.0.1";
static void Main(string[] args)
{
//---create a TCPClient object at the IP and port no.---
TcpClient client = new TcpClient(SERVER_IP, PORT_NO);
NetworkStream nwStream = client.GetStream();
while(true)
{
//---read back the text---
byte[] bytesToRead = new byte[client.ReceiveBufferSize];
int bytesRead = nwStream.Read(bytesToRead, 0, client.ReceiveBufferSize);
Console.WriteLine(Encoding.ASCII.GetString(bytesToRead, 0, bytesRead));
}
}
}
}
Thanks to stack overflow xD
How I can send packets to the server?
EDIT:
I got it, I need to write 1 (for sending) or 0 (for receiving) followed by the command.....
I have an other problem in c#
I can send and receive the packets but i guess the performance is the problem im trying to filter the packages "e_info" and sometimes it displays false packages. Im filtering with this method:
Code:
public Boolean Like(string s,string str)
{
Boolean check = s.Contains(str);
return check;
}
in the main loop Im trying to find the packet like this:
Code:
while (true)
{
//RECEIVE PACKETS
byte[] bytesToRead = new byte[client.ReceiveBufferSize];
int bytesRead = nwStream.Read(bytesToRead, 0, client.ReceiveBufferSize);
string[] packet = { Encoding.ASCII.GetString(bytesToRead, 0, bytesRead) };
DateTime date = DateTime.Now;
foreach (String s in packet)
{
if (instance.Like(s, "0 e_info"))
{
Console.WriteLine("[" + date + "]" + s);
}
}
}
The timestamp also does not appear every time:
[Only registered and activated users can see links. Click Here To Register...]
[Only registered and activated users can see links. Click Here To Register...]