Working with sockets - Server & client [Send - Receive Packets]
Hello Epvps Members .. as title says ..
i am working on client and server deployment on C#
i used Conquer server socket " [Conquer_Online_Server] V 5518+ " and i created a client that connect to it .
i can send and receive bytes and convert it to message like here :
this is Client code :
but now if ia want to create something like conquer login ,, thats contains a text box for Username and another one for Password , and i want send them to server when i click on the login button to check if they are correct or not then pass to login action ,, exactly like conquer online source and client ..
can anyone suggest me how do i start this ??
or anybody create an example " Client " that connects to conquer server and apply my idea ...
Thanx for reading my Thread even if you are will not help :)
Hello Epvps Members .. as title says ..
i am working on client and server deployment on C#
i used Conquer server socket " [Conquer_Online_Server] V 5518+ " and i created a client that connect to it .
i can send and receive bytes and convert it to message like here :
this is Client code :
Code:
private void cmdReceiveData()
{
try
{
while (true)
{
byte[] buffer = new byte[1024];
int iRx = m_socClient.Receive(buffer);
char[] chars = new char[iRx];
System.Text.Decoder d = System.Text.Encoding.UTF8.GetDecoder();
int charLen = d.GetChars(buffer, 0, iRx, chars, 0);
System.String szData = new System.String(chars);
UpdateScreen(szData);
}
}
catch (SocketException se)
{
MessageBox.Show(se.Message);
}
}
private void SendMessage_Click(object sender, EventArgs e)
{
try
{
string objData = TypeMessage.Text;
try
{
Send(m_socClient, Encoding.UTF8.GetBytes(objData), 0, objData.Length, 10000);
}
catch (Exception ex) { /* ... */ }
}
catch (SocketException se)
{
MessageBox.Show(se.Message);
}
}
public static void Send(Socket socket, byte[] buffer, int offset, int size, int timeout)
{
int startTickCount = Environment.TickCount;
int sent = 0; // how many bytes is already sent
do
{
if (Environment.TickCount > startTickCount + timeout)
throw new Exception("Timeout.");
try
{
sent += socket.Send(buffer, offset + sent, size - sent, SocketFlags.None);
}
catch (SocketException ex)
{
if (ex.SocketErrorCode == SocketError.WouldBlock ||
ex.SocketErrorCode == SocketError.IOPending ||
ex.SocketErrorCode == SocketError.NoBufferSpaceAvailable)
{
// socket buffer is probably full, wait and try again
Thread.Sleep(30);
}
else
throw ex; // any serious error occurr
}
} while (sent < size);
}
can anyone suggest me how do i start this ??
or anybody create an example " Client " that connects to conquer server and apply my idea ...
Thanx for reading my Thread even if you are will not help :)