Click here to Skip to main content
15,905,867 members
Home / Discussions / C#
   

C#

 
GeneralRe: filling a dataGridView, editing and overwriting Pin
dan!sh 30-Nov-09 21:20
professional dan!sh 30-Nov-09 21:20 
GeneralRe: filling a dataGridView, editing and overwriting Pin
Emmet_Brown30-Nov-09 21:29
Emmet_Brown30-Nov-09 21:29 
AnswerRe: filling a dataGridView, editing and overwriting Pin
souidi abderrahman30-Nov-09 20:59
souidi abderrahman30-Nov-09 20:59 
GeneralRe: filling a dataGridView, editing and overwriting Pin
Emmet_Brown30-Nov-09 21:08
Emmet_Brown30-Nov-09 21:08 
AnswerRe: filling a dataGridView, editing and overwriting Pin
souidi abderrahman30-Nov-09 21:37
souidi abderrahman30-Nov-09 21:37 
GeneralRe: filling a dataGridView, editing and overwriting Pin
Emmet_Brown30-Nov-09 21:42
Emmet_Brown30-Nov-09 21:42 
QuestionCreate playlist and play using windows media player control Pin
yesu prakash30-Nov-09 18:03
yesu prakash30-Nov-09 18:03 
AnswerRe: Create playlist and play using windows media player control Pin
dan!sh 30-Nov-09 19:29
professional dan!sh 30-Nov-09 19:29 
QuestionObject array problem Pin
CrazyCoder2630-Nov-09 17:53
CrazyCoder2630-Nov-09 17:53 
AnswerRe: Object array problem Pin
dan!sh 30-Nov-09 18:25
professional dan!sh 30-Nov-09 18:25 
GeneralRe: Object array problem Pin
CrazyCoder2630-Nov-09 18:29
CrazyCoder2630-Nov-09 18:29 
GeneralRe: Object array problem Pin
dan!sh 30-Nov-09 18:43
professional dan!sh 30-Nov-09 18:43 
AnswerRe: Object array problem Pin
Blue_Boy30-Nov-09 20:55
Blue_Boy30-Nov-09 20:55 
GeneralRe: Object array problem Pin
vtchris-peterson1-Dec-09 7:20
vtchris-peterson1-Dec-09 7:20 
GeneralRe: Object array problem Pin
CikaPero2-Dec-09 5:05
CikaPero2-Dec-09 5:05 
GeneralRe: Object array problem Pin
Blue_Boy2-Dec-09 6:58
Blue_Boy2-Dec-09 6:58 
AnswerRe: Object array problem Pin
ThatsAlok30-Nov-09 22:42
ThatsAlok30-Nov-09 22:42 
AnswerRe: Object array problem Pin
Shameel1-Dec-09 6:54
professionalShameel1-Dec-09 6:54 
AnswerRe: Object array problem Pin
vtchris-peterson1-Dec-09 7:17
vtchris-peterson1-Dec-09 7:17 
Question[Message Deleted] Pin
arun_pk30-Nov-09 17:32
arun_pk30-Nov-09 17:32 
AnswerWrong Forum Pin
dan!sh 30-Nov-09 17:45
professional dan!sh 30-Nov-09 17:45 
Question[Solved] Client-Server communication Pin
Frank Böttcher30-Nov-09 16:08
Frank Böttcher30-Nov-09 16:08 
Hi;
I'm trying to create a server whose client-handler gets a tcpclient-object and needs to read data.
My problem is: when using the networkstream.read(byte[], offset, length) method, you cant really tell when the client has stopped sending a block.
I tried using while(length == buffer.length) to check if the buffer has been completely filled, meaning there is still data on the stream, but that does not include the possibility that the client has send exactly the amount of bytes the buffer can hold. Then i tried using the DataAvailable-property of the stream, but how does this work when the clients for example sends two different objects, which both happen to have the same size as my buffer? I would read the first object but there would still be data available on the stream since the second object was send right after the first one.
Could someone please point me in the right direction for receiving a variable amount of data representing a custom class / structure over the internet?
MfG Frank

Edit:
Thank you Paulo Zemek for the hint.
On the client side, just serialize the object on the network-stream:
private void sendAction(GameEvent action)<br />
        {<br />
            BinaryFormatter formatter;<br />
<br />
            formatter = new BinaryFormatter();<br />
            formatter.Serialize(this.Server.GetStream(), action);<br />
        }

The server side was a little bit tricky, as I first had to create a new binder for the formatter before deserializing:
using System;<br />
using System.Reflection;<br />
using System.Runtime.Serialization;<br />
<br />
public class Binder : SerializationBinder<br />
{<br />
    public override Type BindToType(string assemblyName, string typeName)<br />
    {<br />
        return Type.GetType(typeName + ", " + Assembly.GetExecutingAssembly().FullName);<br />
    }<br />
}

The deserialization can then be done quite easy:
private void handleClient(Object tcpclient)<br />
        {<br />
            GameEvent action;<br />
            BinaryFormatter formatter;<br />
            TcpClient client;<br />
<br />
            formatter = new BinaryFormatter();<br />
            formatter.Binder = new Binder();<br />
            client = (TcpClient) tcpclient;<br />
<br />
            while (client.Connected)<br />
            {<br />
                try<br />
                {<br />
                    action = (GameEvent) formatter.Deserialize(client.GetStream());<br />
                    this.newAction(client, action);<br />
                }<br />
                catch (Exception)<br />
                {<br />
<br />
                }<br />
            }<br />
            this.Clients.Remove(client);<br />
        }


Thank you again for the great help.
MfG Frank
AnswerRe: Client-Server communication Pin
Jimmanuel1-Dec-09 3:36
Jimmanuel1-Dec-09 3:36 
AnswerRe: Client-Server communication Pin
Paulo Zemek1-Dec-09 5:17
Paulo Zemek1-Dec-09 5:17 
QuestionProblem editing DataGrid Pin
Maxdd 730-Nov-09 14:28
Maxdd 730-Nov-09 14:28 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.