Hi C# friends,...
My code goes like this for creating a library.....
using System;
using System.Collections.Generic;
using System.Text;
using System.Net;
using System.Net.Sockets;
using System.Threading;
namespace ClientLibrary
{
public class ClientLibrary
{
private bool connectionStatus;
private Socket oClientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
private Thread Receiving_Thread = new Thread(receiveFromServer);
public String receivedMessage;
public void connectToMessageServer()
{
try
{
oClientSocket.Connect("CCPCOMP1", 5000);
connectionStatus = true;
Receiving_Thread.Start();
}
catch (Exception exep)
{
connectionStatus = false;
}
}
public void sendToServer(String messageToBeSent)
{
try
{
Encoding ASCII = Encoding.ASCII;
Byte[] messageToBeSentInBytes = ASCII.GetBytes(messageToBeSent);
oClientSocket.Send(messageToBeSentInBytes);
}
catch (Exception exep)
{
}
}
public void receiveFromServer()
{
while (true)
{
try
{
Encoding ASCII = Encoding.ASCII;
Byte[] receiveMessageInBytes = new Byte[100];
oClientSocket.Receive(receiveMessageInBytes);
receivedMessage = ASCII.GetString(receiveMessageInBytes);
}
catch (Exception exep)
{
}
}
}
}
}
When i compile it i get the error
Error 4 A field initializer cannot reference the nonstatic field, method, or property 'ClientLibrary.ClientLibrary.receiveFromServer()' c:\MyFTP\ClientLibrary\ClientLibrary\ClientLibrary\Main.cs 15 54 ClientLibrary
PLease help me outtt.....