Hi,

I have a TCP server running on my desktop. While another TCP client running
on my laptop. Both written in raw C/C++ and they work perfectly fine.

Now I am developing socket application using C# on the same laptop as TCP
client.

It basically connect to the server, send a packet and recv the data. But
what happen is that there is completely no activities going on when I trigge
the function using button. My desktop network activities also complete IDLE
despice several clicks from my C# clients.

Here is my basic logic of codes. I guess there must be some silly mistakes.
Hope you can pin point to me.

Thanks for reading.


MemoryStream f_MemoryStream = new MemoryStream(20);


TcpClient f_Client = new TcpClient();


Byte[] f_DataSend = new Byte[50000];

Byte[] f_DataRecv = new Byte[50000];

f_Client.Connect("192.168.1.2", 8000);

NetworkStream f_Stream = f_Client.GetStream();


f_Stream.Write(f_DataSend, 0, f_DataSend.Length);




Int32 f_LengthRecv = f_Stream.Read(f_DataRecv, 0, f_DataRecv.Length);

f_Client.Close();

f_Stream.Close();

f_MemoryStream.Close();

Re: TCP Socket not working - Logic issue? by Jeroen

Jeroen
Tue Jun 07 04:07:04 CDT 2005

Hi,

This should work... strange...
maybe when you put nothing in the array it won't send a packet???
Try this:

> MemoryStream f_MemoryStream = new MemoryStream(20);
>
>
> TcpClient f_Client = new TcpClient();
>
>
> Byte[] f_DataSend = new Byte[50000];
>
> Byte[] f_DataRecv = new Byte[50000];
>
> f_Client.Connect("192.168.1.2", 8000);
>
> NetworkStream f_Stream = f_Client.GetStream();
>

f_DataSend[0] = 128;
f_DataSend[1] = 128;

>
> f_Stream.Write(f_DataSend, 0, f_DataSend.Length);
>
>
>
>
> Int32 f_LengthRecv = f_Stream.Read(f_DataRecv, 0, f_DataRecv.Length);
>
> f_Client.Close();
>
> f_Stream.Close();
>
> f_MemoryStream.Close();

You can also use the underlying socket and don't use streams... (I do that
most of the time)

TcpClient f_Client = new TcpClient();
Byte[] f_DataSend = new Byte[50000];
Byte[] f_DataRecv = new Byte[50000];
f_Client.Connect("192.168.1.2", 8000);
f_Stream.TcpClient.Send(f_DataSend);
...

But I would put something inside that array first.

Best Regards,

Jeroen Vandezande

--
Join the Object Pascal Revolution - Get Chrome now!
http://www.ChromesVille.com



Re: TCP Socket not working - Logic issue? by Jeroen

Jeroen
Tue Jun 07 04:10:58 CDT 2005


> TcpClient f_Client = new TcpClient();
> Byte[] f_DataSend = new Byte[50000];
> Byte[] f_DataRecv = new Byte[50000];
> f_Client.Connect("192.168.1.2", 8000);
> f_Stream.TcpClient.Send(f_DataSend);


whoops...

that should be:

TcpClient f_Client = new TcpClient();
Byte[] f_DataSend = new Byte[50000];
Byte[] f_DataRecv = new Byte[50000];
f_Client.Connect("192.168.1.2", 8000);
f_Client.TcpClient.Send(f_DataSend);



Re: TCP Socket not working - Logic issue? by Gravity

Gravity
Tue Jun 07 05:59:57 CDT 2005

Hi,

I only see the last line to be different.

However, in my "f_Client", there is no "TcpClient" member function in
compact .net.

Things getting more confussing now..... problem is that it seem right, but
no activities. : (

"Jeroen Vandezande" <nospam@nospam.spam> wrote in message
news:u8O5KD0aFHA.3184@TK2MSFTNGP15.phx.gbl...
>
>> TcpClient f_Client = new TcpClient();
>> Byte[] f_DataSend = new Byte[50000];
>> Byte[] f_DataRecv = new Byte[50000];
>> f_Client.Connect("192.168.1.2", 8000);
>> f_Stream.TcpClient.Send(f_DataSend);
>
>
> whoops...
>
> that should be:
>
> TcpClient f_Client = new TcpClient();
> Byte[] f_DataSend = new Byte[50000];
> Byte[] f_DataRecv = new Byte[50000];
> f_Client.Connect("192.168.1.2", 8000);
> f_Client.TcpClient.Send(f_DataSend);
>
>



Re: TCP Socket not working - Logic issue? by Gravity

Gravity
Tue Jun 07 06:01:58 CDT 2005

In fact, in my actual codes, I do have something for it to send... Just no
response.

By the way, I notice that there is no return value from either functions to
indicate the results? Or its simply did not documented?

"Jeroen Vandezande" <nospam@nospam.spam> wrote in message
news:e3x5$A0aFHA.3932@TK2MSFTNGP12.phx.gbl...
> Hi,
>
> This should work... strange...
> maybe when you put nothing in the array it won't send a packet???
> Try this:
>
>> MemoryStream f_MemoryStream = new MemoryStream(20);
>>
>>
>> TcpClient f_Client = new TcpClient();
>>
>>
>> Byte[] f_DataSend = new Byte[50000];
>>
>> Byte[] f_DataRecv = new Byte[50000];
>>
>> f_Client.Connect("192.168.1.2", 8000);
>>
>> NetworkStream f_Stream = f_Client.GetStream();
>>
>
> f_DataSend[0] = 128;
> f_DataSend[1] = 128;
>
>>
>> f_Stream.Write(f_DataSend, 0, f_DataSend.Length);
>>
>>
>>
>>
>> Int32 f_LengthRecv = f_Stream.Read(f_DataRecv, 0, f_DataRecv.Length);
>>
>> f_Client.Close();
>>
>> f_Stream.Close();
>>
>> f_MemoryStream.Close();
>
> You can also use the underlying socket and don't use streams... (I do that
> most of the time)
>
> TcpClient f_Client = new TcpClient();
> Byte[] f_DataSend = new Byte[50000];
> Byte[] f_DataRecv = new Byte[50000];
> f_Client.Connect("192.168.1.2", 8000);
> f_Stream.TcpClient.Send(f_DataSend);
> ...
>
> But I would put something inside that array first.
>
> Best Regards,
>
> Jeroen Vandezande
>
> --
> Join the Object Pascal Revolution - Get Chrome now!
> http://www.ChromesVille.com
>



Re: TCP Socket not working - Logic issue? by Kevin

Kevin
Tue Jun 07 09:01:01 CDT 2005

Instead of using the TcpClient have you tried just using the Socket class?
Also try doing a flush after your write. Maybe it's buffering it up for some
reason.

"Gravity" wrote:

> In fact, in my actual codes, I do have something for it to send... Just no
> response.
>
> By the way, I notice that there is no return value from either functions to
> indicate the results? Or its simply did not documented?
>
> "Jeroen Vandezande" <nospam@nospam.spam> wrote in message
> news:e3x5$A0aFHA.3932@TK2MSFTNGP12.phx.gbl...
> > Hi,
> >
> > This should work... strange...
> > maybe when you put nothing in the array it won't send a packet???
> > Try this:
> >
> >> MemoryStream f_MemoryStream = new MemoryStream(20);
> >>
> >>
> >> TcpClient f_Client = new TcpClient();
> >>
> >>
> >> Byte[] f_DataSend = new Byte[50000];
> >>
> >> Byte[] f_DataRecv = new Byte[50000];
> >>
> >> f_Client.Connect("192.168.1.2", 8000);
> >>
> >> NetworkStream f_Stream = f_Client.GetStream();
> >>
> >
> > f_DataSend[0] = 128;
> > f_DataSend[1] = 128;
> >
> >>
> >> f_Stream.Write(f_DataSend, 0, f_DataSend.Length);
> >>
> >>
> >>
> >>
> >> Int32 f_LengthRecv = f_Stream.Read(f_DataRecv, 0, f_DataRecv.Length);
> >>
> >> f_Client.Close();
> >>
> >> f_Stream.Close();
> >>
> >> f_MemoryStream.Close();
> >
> > You can also use the underlying socket and don't use streams... (I do that
> > most of the time)
> >
> > TcpClient f_Client = new TcpClient();
> > Byte[] f_DataSend = new Byte[50000];
> > Byte[] f_DataRecv = new Byte[50000];
> > f_Client.Connect("192.168.1.2", 8000);
> > f_Stream.TcpClient.Send(f_DataSend);
> > ...
> >
> > But I would put something inside that array first.
> >
> > Best Regards,
> >
> > Jeroen Vandezande
> >
> > --
> > Join the Object Pascal Revolution - Get Chrome now!
> > http://www.ChromesVille.com
> >
>
>
>

Re: TCP Socket not working - Logic issue? by Jeroen

Jeroen
Tue Jun 07 10:51:56 CDT 2005

> By the way, I notice that there is no return value from either functions
> to indicate the results? Or its simply did not documented?

If you don't get an exception it worked fine...
where you catch the exception you can look at the errorcodes.

Best Regards,

Jeroen Vandezande

--
Join the Object Pascal Revolution - Get Chrome now!
http://www.ChromesVille.com



Re: TCP Socket not working - Logic issue? by Gravity

Gravity
Wed Jun 08 05:56:19 CDT 2005

I was having exception in other codes.

I am currently troubleshooting the codes.

It is the C# nature that do not practise return value checking for each
function call?

"Jeroen Vandezande" <nospam@nospam.spam> wrote in message
news:OZXaQj3aFHA.3864@TK2MSFTNGP10.phx.gbl...
>> By the way, I notice that there is no return value from either functions
>> to indicate the results? Or its simply did not documented?
>
> If you don't get an exception it worked fine...
> where you catch the exception you can look at the errorcodes.
>
> Best Regards,
>
> Jeroen Vandezande
>
> --
> Join the Object Pascal Revolution - Get Chrome now!
> http://www.ChromesVille.com
>



Re: TCP Socket not working - Logic issue? by Jeroen

Jeroen
Thu Jun 09 06:47:50 CDT 2005

"Gravity" <gravity@nospam.org> wrote in message
news:eIcACjBbFHA.1044@TK2MSFTNGP10.phx.gbl...
>I was having exception in other codes.
>
> I am currently troubleshooting the codes.
>
> It is the C# nature that do not practise return value checking for each
> function call?
>

Hi,

You mean that every function call returns 0 when it worked properly and
another code when something went wrong?
Indeed in C# or any .net language this behaviour is handled by exceptions.
note that exceptions are NOT program flow modifiers... so it is only for
functions that normally don't return anything except when an errorcondition
occurs.

Best Regards,

Jeroen Vandezande.

--
Join the Object Pascal Revolution - Get Chrome now!
http://www.ChromesVille.com



Re: TCP Socket not working - Logic issue? by Gravity

Gravity
Sat Jun 11 06:40:00 CDT 2005

I aware of that now. Need to get used to it.


"Jeroen Vandezande" <nospam@nospam.spam> wrote in message
news:%23oMvIkObFHA.612@TK2MSFTNGP12.phx.gbl...
> "Gravity" <gravity@nospam.org> wrote in message
> news:eIcACjBbFHA.1044@TK2MSFTNGP10.phx.gbl...
>>I was having exception in other codes.
>>
>> I am currently troubleshooting the codes.
>>
>> It is the C# nature that do not practise return value checking for each
>> function call?
>>
>
> Hi,
>
> You mean that every function call returns 0 when it worked properly and
> another code when something went wrong?
> Indeed in C# or any .net language this behaviour is handled by exceptions.
> note that exceptions are NOT program flow modifiers... so it is only for
> functions that normally don't return anything except when an
> errorcondition occurs.
>
> Best Regards,
>
> Jeroen Vandezande.
>
> --
> Join the Object Pascal Revolution - Get Chrome now!
> http://www.ChromesVille.com
>