从sparql开始,希望在我的" abstract"中执行显示的SPARQL查询。 div,我遇到了一个我无法消除的错误。 所以我发布我的消息以获得意见(和解决方案?)最终显示我的请求的结果。
这是我的错误:
这是我的剧本:
public class StateObject
{
public Socket workSocket = null;
public const int BufferSize = 4096;
public byte[] buffer = new byte[BufferSize];
public StringBuilder sb = new StringBuilder();
}
public class TcpServerAsync
{
public readonly ConcurrentQueue<String> queue = new ConcurrentQueue<String>();
public ManualResetEvent allDone = new ManualResetEvent(false);
private Boolean _isRunning = true;
public event EventHandler Connected;
public TcpServerAsync(Int32 port)
{
}
public void Start()
{
Thread t = new Thread(Run);
t.Start();
}
public void Run()
{
IPHostEntry ipHostInfo = Dns.GetHostEntry("localhost");
IPAddress ipAddress = ipHostInfo.AddressList[1];
IPEndPoint localEndPoint = new IPEndPoint(ipAddress, 5000);
Socket listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
try
{
listener.Bind(localEndPoint);
listener.Listen(1);
while (_isRunning)
{
allDone.Reset();
listener.BeginAccept(new AsyncCallback(AcceptCallback), listener);
allDone.WaitOne();
}
}
catch (Exception e)
{
Debug.WriteLine(e.ToString());
}
}
public void AcceptCallback(IAsyncResult ar)
{
allDone.Set();
Connected.Invoke(this, new EventArgs());
Socket listener = (Socket)ar.AsyncState;
Socket handler = listener.EndAccept(ar);
StateObject state = new StateObject
{
workSocket = handler
};
handler.BeginReceive(state.buffer, 0, StateObject.BufferSize, 0, new AsyncCallback(ReadCallback), state);
while (handler.Connected)
{
if (queue.TryDequeue(out String data))
{
try
{
SendData(handler, data);
}
catch (Exception ex)
{
throw;
}
}
Thread.Sleep(0);
}
}
public void ReadCallback(IAsyncResult ar)
{
String content = String.Empty;
StateObject state = (StateObject)ar.AsyncState;
Socket handler = state.workSocket;
int bytesRead = handler.EndReceive(ar);
if (bytesRead > 0)
{
state.sb.Append(Encoding.ASCII.GetString(state.buffer, 0, bytesRead));
content = state.sb.ToString();
Debug.WriteLine("Read {0} bytes from socket. \n Data : {1}", content.Length, content);
}
}
public void SendData(Socket handler, String data)
{
byte[] byteData = Encoding.ASCII.GetBytes(data);
handler.BeginSend(byteData, 0, byteData.Length, 0, new AsyncCallback(SendCallback), handler);
}
private void SendCallback(IAsyncResult ar)
{
try
{
Socket handler = (Socket)ar.AsyncState;
int bytesSent = handler.EndSend(ar);
Debug.WriteLine("Sent {0} bytes to client.", bytesSent);
}
catch (Exception e)
{
Debug.WriteLine(e.ToString());
}
}
}