Welcome Guest Search | Active Topics | Members | Log In | Register

Stream Data Options
troy
Posted: Monday, December 22, 2008 7:20:54 AM
Rank: Member
Groups: Member

Joined: 12/22/2008
Posts: 3
Points: 9
Hello,

It has been nice performing simple server/client tests with the XF.Server control over the past 24hrs. We now want to start implementing into our current project, but would appreciate any feedback in the following scenario:
1. Server Starts Listening (Network.AcceptAsync....)
2. Client ConnectAsync, onConnectComplete calls server.ReadAsync(delegate) and waits
3. Server begins to stream 1 - 8192byte data buffers

This is where we are running into problems, as we seem to only get the first buffer to the client. In the client readcomplete delegate, we are

buffer.Acquire();
work on buffer data
buffer.Release
calling connection.ReadAsync(delegate) ready for next buffer of data from server

We are missing something, if someone could provide additional help so we can overcome this problem. The final objective would be a open connection between client and server with constant flow of adhoc data at any time, any buffer length, either end.

Kind Regards,
Troy
admin
Posted: Monday, December 22, 2008 12:24:01 PM
Rank: Administration
Groups: Administration

Joined: 2/15/2008
Posts: 130
Points: 835
Can you post your code(prototype) (client and server) ?
troy
Posted: Monday, December 22, 2008 1:05:38 PM
Rank: Member
Groups: Member

Joined: 12/22/2008
Posts: 3
Points: 9
Thank you, below is the basic code/concept we need:

SERVER:
private void StartTCPServer()
{
using (var listener =
Network.AcceptAsync(new IPEndPoint(IPAddress.Any, 4040),
ProcessClient, new ExtendedParameters { BufferSize = 8192, Optimized = false }))
{
Console.WriteLine("Server is ready to accept connections at {0}.", listener.EndPoint);
Console.WriteLine("Press any key to exit.");
Console.ReadKey(true);
}
}

private static void ProcessClient(IConnection connection)
{
WriteCompleteDelegate c = new WriteCompleteDelegate(WriteComplete);

List<byte[]> dataList = GetData();//reason for this List is each byte[8192] has its own mini header
foreach (byte[] data in dataList)
{
connection.WriteAsync(data, c);
}

}

public static void WriteComplete(IConnection connection, int i)
{
}



CLIENT:
public string Connect3()
{
data = new List<PacketStaffHeader>();

Network.ConnectAsync(new IPEndPoint(IPAddress.Parse(serverIP), 4040), OnConnectComplete, OnConnectError);

return string.Empty;
}


private void OnConnectError(int errorCode)
{
Console.WriteLine("Error code: {0}", errorCode);
}



private void OnConnectComplete(IConnection server)
{
ReadCompleteDelegate c = new ReadCompleteDelegate(ReadComplete);

server.ReadAsync(c);
}

private static List<PacketStaffHeader> data = new List<PacketStaffHeader>();

public static void ReadComplete(IConnection server, IMemoryBuffer buffer)
{
if (buffer == null) return;
buffer.Acquire();
PacketHeader header = new PacketStuff().UnpackHeader(buffer.Data);
buffer.Release();
data.Add(header);
if (data.Count == header.PacketCount)
{
ProcessAllData(data);
}
ReadCompleteDelegate c = new ReadCompleteDelegate(ReadComplete);
server.ReadAsync(c);
}
admin
Posted: Monday, December 22, 2008 1:39:52 PM
Rank: Administration
Groups: Administration

Joined: 2/15/2008
Posts: 130
Points: 835
Here are some notes:
Server seems to be ok, but the client should be modified.

1. buffer.Acquire and buffer.Release should be used if buffer is used in asynchronous operation, otherwise it is useless.
In your code:
Code:
buffer.Acquire();
PacketHeader header = new PacketStuff().UnpackHeader(buffer.Data);
buffer.Release();
data.Add(header);

we see that buffer not processed asynchronously.

2. buffer.Data is a location for data, but actual data is placed starting from buffer.Offset till buffer.Offset + buffer.BytesTransfered, you should consider that when you process data in:
Code:
PacketHeader header = new PacketStuff().UnpackHeader(buffer.Data);


Please try these fixes and inform about the results. Be aware of the fact that you may receive several packets, or a partial packet during one ReadAsync operation. Your code should be able to do the framing(split incoming data into the packets).
Users browsing this topic
Guest


Forum Jump
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Main Forum RSS : RSS

YAFPro Theme Created by Jaben Cargman (Tiny Gecko)
Powered by Yet Another Forum.net version 1.9.1.6 (NET v2.0) - 11/14/2007
Copyright © 2003-2006 Yet Another Forum.net. All rights reserved.
This page was generated in 0.091 seconds.
11 queries (0.026 seconds, 28.57%).

yaf_pageload: 0.005
yaf_topic_info: 0.001
yaf_forum_list: 0.001
yaf_forum_listpath: 0.001
yaf_forum_listpath: 0.001
yaf_post_list: 0.010
yaf_usergroup_list: 0.001
yaf_usergroup_list: 0.003
yaf_usergroup_list: 0.001
yaf_usergroup_list: 0.001
yaf_active_listtopic: 0.001