|
I wanted to do the same thing and found some code
similar to what kalyanPaladugu posted in the msdn.
At least for me it seemed to work well.
I guess creating a custom cell type also has
its charme. I will use that idea when I want to do
a little more than just do some painting.
Thanks for the tip,
Erik
|
|
|
|
|
Hi
Sending objects over a wire from a client to a server. I 'serialise' the object on the client, send, via a Socket, and deserialise on server. Cool. Works a treat....for one object.
Whilst the server is handling the object I've sent, I might have sent three or four more, so when the server finally gets round to reading the socket stream again, it pulls in byte[] containing multiple serialised objects. Throwing that at my deserialise method fails. Do I have to manually tokensize the byte[] before sending and then on the server parse for the tokens? This could be a) slow as the tokens could be very large and b) not guarenteed, as the tokens I use could actually be part of the data in the serialised object, which would cause the deserialise to split in the wrong place.
Any ideas? Current code below
public void Go()
{
socket.BeginReceive(cs.RcvBuffer , 0 , cs.RcvBuffer.Length , SocketFlags.None , new AsyncCallback(ReadCallback), cs);
}
protected void ReadCallback(IAsyncResult ar)
{
clientState cs = (clientState)ar.AsyncState;
try
{
int recvMsgSize = cs.ClntSock.EndReceive(ar);
if (recvMsgSize > 0)
{
cs.TotalBytes += recvMsgSize;
Console.WriteLine("Thread {0} - ReadCallback(): total received {1} bytes",
ID,
cs.TotalBytes);
SocketTest.MyTestClass m = Decode(cs.RcvBuffer);
DoSomethingWithMyTestClass( m );
Go();
}
}
catch(SocketException se)
{
Console.WriteLine(se.ErrorCode + ":" + se.Message);
}
}
public SocketTest.MyTestClass Decode(byte[] theByteArray)
{
Console.WriteLine("Decoding {0} bytes", theByteArray.Length);
MemoryStream ms = new MemoryStream(theByteArray);
BinaryFormatter bf1 = new BinaryFormatter();
ms.Position = 0;
return (SocketTest.MyTestClass)bf1.Deserialize(ms);
}
Regards
Malc
*********************************************
|
|
|
|
|
Sorry, should have tried harder before posting....but it just clicked!
Easy - pass down the number of bytes recieved to the decode, and keep decoding until the position in the memorystream exceeds the number of bytes passed
New Code :
<br />
<br />
...snip....<br />
if (recvMsgSize > 0)<br />
{<br />
cs.TotalBytes += recvMsgSize;<br />
<br />
Console.WriteLine("Thread {0} - ReadCallback(): total received {1} bytes",<br />
ID,<br />
cs.TotalBytes);<br />
Decode(cs.RcvBuffer , recvMsgSize);<br />
<br />
<br />
public void Decode(byte[] theByteArray , long SizeOfBuffer)<br />
{<br />
Console.WriteLine("Decoding {0} bytes", SizeOfBuffer);<br />
MemoryStream ms = new MemoryStream(theByteArray);<br />
BinaryFormatter bf1 = new BinaryFormatter();<br />
ms.Position = 0;<br />
<br />
while (ms.Position < SizeOfBuffer)<br />
{<br />
SocketTest.Message m = (SocketTest.Message)bf1.Deserialize(ms);<br />
DoSomethingWithMyTestClass(m);<br />
}<br />
<br />
}<br />
<br />
<br />
<br />
Regards
Malc
*********************************************
|
|
|
|
|
You could add a header that contains the number of objects being transmitted and the size of each object in bytes. The tricky bit would be that since the number of objects being transmitted can vary, so too will the size of the header.
An alternative would be to add each object being transmitted to a container and then serialize/transmit/deserialize the container and then deserialize each object in the container.
|
|
|
|
|
They are being sent from the client one at a time, varying length. The stream gets concatonated at teh server side whilst I am handling a previous read.
I sussed it out partially, as deserialise nicely moves the pointer in the memory stram to the start of the next object. My current issue is handling partial data. After calling BeginRecieve, EndReceive, my byte[] buffer sometimes has only half an object, the other half is still sitting in the stream waiting for the next BeginReceive call.
I tried to resolve this by holding a pointer to the start of the incomplete point in the stream, set the offset in the BeginRecieve to the end of the current stream and read, ensuring I get the rest of the data, but somewhere down the line my logic screws up as I miss shed loads of messages.
So...I sound like my wife, rambling on and on and on here....
I am changing it to do what you said, pass a 4 byte header which contains the length. On the asynch beginrecieve, specify 4 bytes as the size to read, then call a blocking read to read the rest, pass that off to another thread to handler the deserialise, and then start again, beginReceive for the next four byte size.
I know there are loads of client servers socket examples around on CP, but you can't learn better that rolling your own from scratch, and then seeing how others have done it.
Regards
Malc
*********************************************
|
|
|
|
|
how can parser this string "casa-de-paco" in three differents strings "casa" "de" "paco" thanks
Dios creo un equipo perfecto a los demas los lleno de extranjeros
|
|
|
|
|
I don't understand the referrence to Java, but this might be what you want:
string original = "casa-de-paco";
string tokens[] = original.Split('-');
|
|
|
|
|
Colin Angus Mackay wrote: I don't understand the referrence to Java
Java's StringTokenizer[^] object allows you to split strings into parts ("tokens"); I think he was looking for and equivalent. string.Split should work in this case, though, as you mention.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Messianic Instrumentals (with audio)
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
thanks both
Dios creo un equipo perfecto a los demas los lleno de extranjeros
|
|
|
|
|
How to access the value inserted in a windows application form into a class library created of your own ? the namespace created is included in the window application.
|
|
|
|
|
digitalangel wrote: ed in a windows application form into a class library created of your own ?
Could you rephrase that question? I don't understand what you're asking.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Messianic Instrumentals (with audio)
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
Iam displaying data and image in dataGridView. Iam using a datatable as a datasource for my datagridview. The problem i have is with the image.
I defined a column like this
dt.Columns.Add(new DataColumn("Col", typeof(System.Drawing.Bitmap)));
where dt is datatable.
Now when i use this dt as my datasource to my dataGridView by default it keeps a cross image in that column(for all rows) if the image is not there. is there a way to make it display nothing in the column if the image is not there.
I need the solution urgently please help
Thanks
Kal
|
|
|
|
|
2 options I see: if the image isn't there, use set image to a blank image. The other option is, derive a custom DataGridView cell type and, during the paint override, draw nothing if the image isn't there.
Tech, life, family, faith: Give me a visit.
I'm currently blogging about: Messianic Instrumentals (with audio)
The apostle Paul, modernly speaking: Epistles of Paul
Judah Himango
|
|
|
|
|
Thanks for replying
1. How do i set the image to the blank image. Should i create a blank image
before hand. Can you please post some code reagarding it.
2. Second seems to be the way to do it. Can you please post some code how to
derive a custom DataGridView Cell type and draw nothing if the image isnt
there.
I dont have much experience in doing user interfaces even though i did lot of server side work in c#.
iam waiting for your reply
Thanks
Kal
|
|
|
|
|
|
How can I alignment text from right to left???
When I print text to printer.
like this :
XXXXXXXX
XXXXX
XXX
XXXXXX
and not like this :
XXXXXXXX
XXXXX
XXX
XXXXXX
I use this command to print:
e.Graphics.DrawString(..............)
I Work with type of size - millimeter.
help me PLEASE !!!!!!!!!!!!!!!!!!!!!!!
|
|
|
|
|
StingFormat myStringFormat = new StringFormat(StringFormatFlags.DirectionRightToLeft);
myStringFormat.LineAlignMent = StringAlignment.Near;
myStringFormat.Alignmet = StringAlignment.Center;
e.Graphics.DrawString(myStrinf,myFont,myBrush,x,y,myStringFormat.)
|
|
|
|
|
Can we access private variables of base class
from the derived class methods?
Thanks,
...G.
|
|
|
|
|
No. Members that need to be accessible by derived classes should be declared protected (or public if they should also be accessible by clients).
/ravi
|
|
|
|
|
Thanks Ravi!
Do you know why the feature of specifying the inheritance at the class level is not provided there unlike C++? Are you getting what I am trying to say?
e.g. can we write,
class MyDerivedClass : Private MyBaseClass
in C#.
If we can't then why?
Have a nice day!
Thanks,
...G.
|
|
|
|
|
Inheritance in C# has been designed to be more formal than C++. Along with explicit inheritance rules, C# also restricts class inheritance to a single base class (although it does permit a class to implement any number of interfaces).
/ravi
|
|
|
|
|
Hi,
does anybody know a printer controller for Visual 2003?
I would like to make a function that will print directly after clicking on a button.
Thanks,
Oren
|
|
|
|
|
You actually expect us to view *all* of those?
Aside from the fact that they appear to have been stolen from traincert, why would I want to do that?
The posting is almost certainly a copyright violation.
My idea is that you should remove the postings and delete you post before the publisher of those training videos sues you, or charges you with theft.
|
|
|
|
|
Hello,
(call it my laziness or my haste that I am post a question straight here instead of consulting the reference books)
I have a point class in my project called FoxPoint, can I make a 2D array like this:
FoxPoint[,] strokes = new FoxPoint[4, 10];
It's giving me strange errors:
Error 1 Inconsistent accessibility: parameter type FOX_CSharp.FoxPoint[*,*]' is less accessible than method 'FOX_CSharp.ConComp2Form.DrawBoundries(FOX_CSharp.FoxPoint[*,*])' C:\...\FOX_CSharp - Integrated - Aug 05 06\FOX_CSharp\ConComp2Form.cs 195 21 FOX_CSharp
- A programmer's national anthem; "AAAAAHHHHH!!!!"
|
|
|
|
|
You have something wrong with "public" and "private". Change all to private or change all to public to solve it. See this:
http://www.dotnet247.com/247reference/msgs/7/38448.aspx
|
|
|
|