Hi , i have problem about sending data over socket . It waits for another
socket.send
// str = Encoding.ASCII.GetBytes("hello");
socket.Send(str,0,str.Length,SocketFlags.None);
socket.Receive(strincome,0,socket.Available,Socket Flags.None); // return
"hello to you "
// str =Encoding.ASCII.GetBytes( "how_are_you ");
socket.Send(str,0,str.Length,SocketFlags.None);
socket.Receive(strincome,0,socket.Available,Socket Flags.None);// return
"fine"
it sends like this "hellohow_are_you" , but it is wrong , how can i solve it
?
thanks in advance 11 2021
Hi,
Simple, you have to either send a terminator or before sending the string
send the # of bytes you will send.
cheers,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Hasan O" <ho********@gmail.com> wrote in message
news:uU**************@TK2MSFTNGP12.phx.gbl... Hi , i have problem about sending data over socket . It waits for another socket.send
// str = Encoding.ASCII.GetBytes("hello");
socket.Send(str,0,str.Length,SocketFlags.None);
socket.Receive(strincome,0,socket.Available,Socket Flags.None); // return "hello to you "
// str =Encoding.ASCII.GetBytes( "how_are_you ");
socket.Send(str,0,str.Length,SocketFlags.None);
socket.Receive(strincome,0,socket.Available,Socket Flags.None);// return "fine" it sends like this "hellohow_are_you" , but it is wrong , how can i solve it ? thanks in advance
Hi Ignacio ,
there is no such thing . when i run it command by command ( debug ) it works
correctly .
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote
in message news:uN*************@tk2msftngp13.phx.gbl... Hi,
Simple, you have to either send a terminator or before sending the string send the # of bytes you will send.
cheers,
-- Ignacio Machin, ignacio.machin AT dot.state.fl.us Florida Department Of Transportation
"Hasan O" <ho********@gmail.com> wrote in message news:uU**************@TK2MSFTNGP12.phx.gbl... Hi , i have problem about sending data over socket . It waits for another socket.send
// str = Encoding.ASCII.GetBytes("hello");
socket.Send(str,0,str.Length,SocketFlags.None);
socket.Receive(strincome,0,socket.Available,Socket Flags.None); // return "hello to you "
// str =Encoding.ASCII.GetBytes( "how_are_you ");
socket.Send(str,0,str.Length,SocketFlags.None);
socket.Receive(strincome,0,socket.Available,Socket Flags.None);// return "fine" it sends like this "hellohow_are_you" , but it is wrong , how can i solve it ? thanks in advance
Is that because you are stepping through line by line? socket.Send(str,0,str.Length,SocketFlags.None);
socket.Receive(strincome,0,socket.Available,Socket Flags.None); // return "hello to you "
That use of socket.Available is the problem. If execution goes too quickly,
the receive will get called before the remote client has time to actually
send anything. Thus socket.Available = 0. And the receive immediately
returns without actually receiving anythign. It then goes on to send the
next bit.
My guess is, this is all happening so fast that it all looks like one string
on the remote end.
--
Adam Clauss
"Hasan O" <ho********@gmail.com> wrote in message
news:eT**************@TK2MSFTNGP11.phx.gbl... Hi Ignacio , there is no such thing . when i run it command by command ( debug ) it works correctly .
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote in message news:uN*************@tk2msftngp13.phx.gbl... Hi,
Simple, you have to either send a terminator or before sending the string send the # of bytes you will send.
cheers,
-- Ignacio Machin, ignacio.machin AT dot.state.fl.us Florida Department Of Transportation
"Hasan O" <ho********@gmail.com> wrote in message news:uU**************@TK2MSFTNGP12.phx.gbl... Hi , i have problem about sending data over socket . It waits for another socket.send
// str = Encoding.ASCII.GetBytes("hello");
socket.Send(str,0,str.Length,SocketFlags.None);
socket.Receive(strincome,0,socket.Available,Socket Flags.None); // return "hello to you "
// str =Encoding.ASCII.GetBytes( "how_are_you ");
socket.Send(str,0,str.Length,SocketFlags.None);
socket.Receive(strincome,0,socket.Available,Socket Flags.None);// return "fine" it sends like this "hellohow_are_you" , but it is wrong , how can i solve it ? thanks in advance
yes , you are right . So what would be the solution ?
"Adam Clauss" <ca*****@tamu.edu> wrote in message
news:11*************@corp.supernews.com... Is that because you are stepping through line by line?
socket.Send(str,0,str.Length,SocketFlags.None);
socket.Receive(strincome,0,socket.Available,Socket Flags.None); // return "hello to you "
That use of socket.Available is the problem. If execution goes too quickly, the receive will get called before the remote client has time to actually send anything. Thus socket.Available = 0. And the receive immediately returns without actually receiving anythign. It then goes on to send the next bit.
My guess is, this is all happening so fast that it all looks like one string on the remote end.
-- Adam Clauss
"Hasan O" <ho********@gmail.com> wrote in message news:eT**************@TK2MSFTNGP11.phx.gbl... Hi Ignacio , there is no such thing . when i run it command by command ( debug ) it works correctly .
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote in message news:uN*************@tk2msftngp13.phx.gbl... Hi,
Simple, you have to either send a terminator or before sending the string send the # of bytes you will send.
cheers,
-- Ignacio Machin, ignacio.machin AT dot.state.fl.us Florida Department Of Transportation
"Hasan O" <ho********@gmail.com> wrote in message news:uU**************@TK2MSFTNGP12.phx.gbl... Hi , i have problem about sending data over socket . It waits for another socket.send
// str = Encoding.ASCII.GetBytes("hello");
socket.Send(str,0,str.Length,SocketFlags.None);
socket.Receive(strincome,0,socket.Available,Socket Flags.None); // return "hello to you "
// str =Encoding.ASCII.GetBytes( "how_are_you ");
socket.Send(str,0,str.Length,SocketFlags.None);
socket.Receive(strincome,0,socket.Available,Socket Flags.None);// return "fine" it sends like this "hellohow_are_you" , but it is wrong , how can i solve it ? thanks in advance
by the way ,
//socket.SetSocketOption(SocketOptionLevel.Socket,So cketOptionName.ReceiveTimeout,5000);
//socket.SetSocketOption(SocketOptionLevel.Socket,So cketOptionName.SendTimeout,5000);
these dont work
"Hasan O" <ho********@gmail.com> wrote in message
news:Os***************@TK2MSFTNGP11.phx.gbl... yes , you are right . So what would be the solution ?
You do what Ignacio recommended :)
You send the length first.
Length should be fixed-length, so you know exactly how many bytes you are
waiting for. And then from the length you get, you can do another
Receive().
--
Adam Clauss
Hi,
The one I told you the first time, use either a terminator or send before
the number of bytes
cheers,
--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
"Hasan O" <ho********@gmail.com> wrote in message
news:Os***************@TK2MSFTNGP11.phx.gbl... yes , you are right . So what would be the solution ?
"Adam Clauss" <ca*****@tamu.edu> wrote in message news:11*************@corp.supernews.com... Is that because you are stepping through line by line?
> socket.Send(str,0,str.Length,SocketFlags.None); > > socket.Receive(strincome,0,socket.Available,Socket Flags.None); // > return "hello to you "
That use of socket.Available is the problem. If execution goes too quickly, the receive will get called before the remote client has time to actually send anything. Thus socket.Available = 0. And the receive immediately returns without actually receiving anythign. It then goes on to send the next bit.
My guess is, this is all happening so fast that it all looks like one string on the remote end.
-- Adam Clauss
"Hasan O" <ho********@gmail.com> wrote in message news:eT**************@TK2MSFTNGP11.phx.gbl... Hi Ignacio , there is no such thing . when i run it command by command ( debug ) it works correctly .
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote in message news:uN*************@tk2msftngp13.phx.gbl... Hi,
Simple, you have to either send a terminator or before sending the string send the # of bytes you will send.
cheers,
-- Ignacio Machin, ignacio.machin AT dot.state.fl.us Florida Department Of Transportation
"Hasan O" <ho********@gmail.com> wrote in message news:uU**************@TK2MSFTNGP12.phx.gbl... > Hi , i have problem about sending data over socket . It waits for > another socket.send > > // str = Encoding.ASCII.GetBytes("hello"); > > socket.Send(str,0,str.Length,SocketFlags.None); > > socket.Receive(strincome,0,socket.Available,Socket Flags.None); // > return "hello to you " > > // str =Encoding.ASCII.GetBytes( "how_are_you "); > > socket.Send(str,0,str.Length,SocketFlags.None); > > socket.Receive(strincome,0,socket.Available,Socket Flags.None);// > return "fine" > > > > it sends like this "hellohow_are_you" , but it is wrong , how can i > solve it ? > > > > thanks in advance > >
Hi ,
the other side only accepts strings without a terminator character . lets
say it waits for "hello" . Also , it doesnt accept how many bytes it gonna
take. I simply send "hello" and it gives me "hello back". but when i use
sequential send , my program merges all send commands.
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote
in message news:u7**************@TK2MSFTNGP11.phx.gbl... Hi,
The one I told you the first time, use either a terminator or send before the number of bytes
cheers,
-- Ignacio Machin, ignacio.machin AT dot.state.fl.us Florida Department Of Transportation
"Hasan O" <ho********@gmail.com> wrote in message news:Os***************@TK2MSFTNGP11.phx.gbl... yes , you are right . So what would be the solution ?
"Adam Clauss" <ca*****@tamu.edu> wrote in message news:11*************@corp.supernews.com... Is that because you are stepping through line by line?
>> socket.Send(str,0,str.Length,SocketFlags.None); >> >> socket.Receive(strincome,0,socket.Available,Socket Flags.None); // >> return "hello to you "
That use of socket.Available is the problem. If execution goes too quickly, the receive will get called before the remote client has time to actually send anything. Thus socket.Available = 0. And the receive immediately returns without actually receiving anythign. It then goes on to send the next bit.
My guess is, this is all happening so fast that it all looks like one string on the remote end.
-- Adam Clauss
"Hasan O" <ho********@gmail.com> wrote in message news:eT**************@TK2MSFTNGP11.phx.gbl... Hi Ignacio , there is no such thing . when i run it command by command ( debug ) it works correctly .
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote in message news:uN*************@tk2msftngp13.phx.gbl... > Hi, > > Simple, you have to either send a terminator or before sending the > string send the # of bytes you will send. > > cheers, > > -- > Ignacio Machin, > ignacio.machin AT dot.state.fl.us > Florida Department Of Transportation > > > "Hasan O" <ho********@gmail.com> wrote in message > news:uU**************@TK2MSFTNGP12.phx.gbl... >> Hi , i have problem about sending data over socket . It waits for >> another socket.send >> >> // str = Encoding.ASCII.GetBytes("hello"); >> >> socket.Send(str,0,str.Length,SocketFlags.None); >> >> socket.Receive(strincome,0,socket.Available,Socket Flags.None); // >> return "hello to you " >> >> // str =Encoding.ASCII.GetBytes( "how_are_you "); >> >> socket.Send(str,0,str.Length,SocketFlags.None); >> >> socket.Receive(strincome,0,socket.Available,Socket Flags.None);// >> return "fine" >> >> >> >> it sends like this "hellohow_are_you" , but it is wrong , how can i >> solve it ? >> >> >> >> thanks in advance >> >> > >
Hi ,
the other side only accepts strings without a terminator character . lets
say it waits for "hello" . Also , it doesnt accept how many bytes it gonna
take. I simply send "hello" and it gives me "hello back". but when i use
sequential send , my program merges all send commands.
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote
in message news:u7**************@TK2MSFTNGP11.phx.gbl... Hi,
The one I told you the first time, use either a terminator or send before the number of bytes
cheers,
-- Ignacio Machin, ignacio.machin AT dot.state.fl.us Florida Department Of Transportation
"Hasan O" <ho********@gmail.com> wrote in message news:Os***************@TK2MSFTNGP11.phx.gbl... yes , you are right . So what would be the solution ?
"Adam Clauss" <ca*****@tamu.edu> wrote in message news:11*************@corp.supernews.com... Is that because you are stepping through line by line?
>> socket.Send(str,0,str.Length,SocketFlags.None); >> >> socket.Receive(strincome,0,socket.Available,Socket Flags.None); // >> return "hello to you "
That use of socket.Available is the problem. If execution goes too quickly, the receive will get called before the remote client has time to actually send anything. Thus socket.Available = 0. And the receive immediately returns without actually receiving anythign. It then goes on to send the next bit.
My guess is, this is all happening so fast that it all looks like one string on the remote end.
-- Adam Clauss
"Hasan O" <ho********@gmail.com> wrote in message news:eT**************@TK2MSFTNGP11.phx.gbl... Hi Ignacio , there is no such thing . when i run it command by command ( debug ) it works correctly .
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote in message news:uN*************@tk2msftngp13.phx.gbl... > Hi, > > Simple, you have to either send a terminator or before sending the > string send the # of bytes you will send. > > cheers, > > -- > Ignacio Machin, > ignacio.machin AT dot.state.fl.us > Florida Department Of Transportation > > > "Hasan O" <ho********@gmail.com> wrote in message > news:uU**************@TK2MSFTNGP12.phx.gbl... >> Hi , i have problem about sending data over socket . It waits for >> another socket.send >> >> // str = Encoding.ASCII.GetBytes("hello"); >> >> socket.Send(str,0,str.Length,SocketFlags.None); >> >> socket.Receive(strincome,0,socket.Available,Socket Flags.None); // >> return "hello to you " >> >> // str =Encoding.ASCII.GetBytes( "how_are_you "); >> >> socket.Send(str,0,str.Length,SocketFlags.None); >> >> socket.Receive(strincome,0,socket.Available,Socket Flags.None);// >> return "fine" >> >> >> >> it sends like this "hellohow_are_you" , but it is wrong , how can i >> solve it ? >> >> >> >> thanks in advance >> >> > >
So do you explicity know how many bytes you receive as a response then? If
that is predefined, then use that instead of Available.
--
Adam Clauss
"Hasan O" <ho********@gmail.com> wrote in message
news:uT**************@TK2MSFTNGP12.phx.gbl... Hi , the other side only accepts strings without a terminator character . lets say it waits for "hello" . Also , it doesnt accept how many bytes it gonna take. I simply send "hello" and it gives me "hello back". but when i use sequential send , my program merges all send commands.
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote in message news:u7**************@TK2MSFTNGP11.phx.gbl... Hi,
The one I told you the first time, use either a terminator or send before the number of bytes
cheers,
-- Ignacio Machin, ignacio.machin AT dot.state.fl.us Florida Department Of Transportation
"Hasan O" <ho********@gmail.com> wrote in message news:Os***************@TK2MSFTNGP11.phx.gbl... yes , you are right . So what would be the solution ?
"Adam Clauss" <ca*****@tamu.edu> wrote in message news:11*************@corp.supernews.com... Is that because you are stepping through line by line?
>>> socket.Send(str,0,str.Length,SocketFlags.None); >>> >>> socket.Receive(strincome,0,socket.Available,Socket Flags.None); // >>> return "hello to you "
That use of socket.Available is the problem. If execution goes too quickly, the receive will get called before the remote client has time to actually send anything. Thus socket.Available = 0. And the receive immediately returns without actually receiving anythign. It then goes on to send the next bit.
My guess is, this is all happening so fast that it all looks like one string on the remote end.
-- Adam Clauss
"Hasan O" <ho********@gmail.com> wrote in message news:eT**************@TK2MSFTNGP11.phx.gbl... > Hi Ignacio , > there is no such thing . when i run it command by command ( debug ) it > works correctly . > > > "Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> > wrote in message news:uN*************@tk2msftngp13.phx.gbl... >> Hi, >> >> Simple, you have to either send a terminator or before sending the >> string send the # of bytes you will send. >> >> cheers, >> >> -- >> Ignacio Machin, >> ignacio.machin AT dot.state.fl.us >> Florida Department Of Transportation >> >> >> "Hasan O" <ho********@gmail.com> wrote in message >> news:uU**************@TK2MSFTNGP12.phx.gbl... >>> Hi , i have problem about sending data over socket . It waits for >>> another socket.send >>> >>> // str = Encoding.ASCII.GetBytes("hello"); >>> >>> socket.Send(str,0,str.Length,SocketFlags.None); >>> >>> socket.Receive(strincome,0,socket.Available,Socket Flags.None); // >>> return "hello to you " >>> >>> // str =Encoding.ASCII.GetBytes( "how_are_you "); >>> >>> socket.Send(str,0,str.Length,SocketFlags.None); >>> >>> socket.Receive(strincome,0,socket.Available,Socket Flags.None);// >>> return "fine" >>> >>> >>> >>> it sends like this "hellohow_are_you" , but it is wrong , how can i >>> solve it ? >>> >>> >>> >>> thanks in advance >>> >>> >> >> > >
So do you explicity know how many bytes you receive as a response then? If
that is predefined, then use that instead of Available.
--
Adam Clauss
"Hasan O" <ho********@gmail.com> wrote in message
news:uT**************@TK2MSFTNGP12.phx.gbl... Hi , the other side only accepts strings without a terminator character . lets say it waits for "hello" . Also , it doesnt accept how many bytes it gonna take. I simply send "hello" and it gives me "hello back". but when i use sequential send , my program merges all send commands.
"Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> wrote in message news:u7**************@TK2MSFTNGP11.phx.gbl... Hi,
The one I told you the first time, use either a terminator or send before the number of bytes
cheers,
-- Ignacio Machin, ignacio.machin AT dot.state.fl.us Florida Department Of Transportation
"Hasan O" <ho********@gmail.com> wrote in message news:Os***************@TK2MSFTNGP11.phx.gbl... yes , you are right . So what would be the solution ?
"Adam Clauss" <ca*****@tamu.edu> wrote in message news:11*************@corp.supernews.com... Is that because you are stepping through line by line?
>>> socket.Send(str,0,str.Length,SocketFlags.None); >>> >>> socket.Receive(strincome,0,socket.Available,Socket Flags.None); // >>> return "hello to you "
That use of socket.Available is the problem. If execution goes too quickly, the receive will get called before the remote client has time to actually send anything. Thus socket.Available = 0. And the receive immediately returns without actually receiving anythign. It then goes on to send the next bit.
My guess is, this is all happening so fast that it all looks like one string on the remote end.
-- Adam Clauss
"Hasan O" <ho********@gmail.com> wrote in message news:eT**************@TK2MSFTNGP11.phx.gbl... > Hi Ignacio , > there is no such thing . when i run it command by command ( debug ) it > works correctly . > > > "Ignacio Machin ( .NET/ C# MVP )" <ignacio.machin AT dot.state.fl.us> > wrote in message news:uN*************@tk2msftngp13.phx.gbl... >> Hi, >> >> Simple, you have to either send a terminator or before sending the >> string send the # of bytes you will send. >> >> cheers, >> >> -- >> Ignacio Machin, >> ignacio.machin AT dot.state.fl.us >> Florida Department Of Transportation >> >> >> "Hasan O" <ho********@gmail.com> wrote in message >> news:uU**************@TK2MSFTNGP12.phx.gbl... >>> Hi , i have problem about sending data over socket . It waits for >>> another socket.send >>> >>> // str = Encoding.ASCII.GetBytes("hello"); >>> >>> socket.Send(str,0,str.Length,SocketFlags.None); >>> >>> socket.Receive(strincome,0,socket.Available,Socket Flags.None); // >>> return "hello to you " >>> >>> // str =Encoding.ASCII.GetBytes( "how_are_you "); >>> >>> socket.Send(str,0,str.Length,SocketFlags.None); >>> >>> socket.Receive(strincome,0,socket.Available,Socket Flags.None);// >>> return "fine" >>> >>> >>> >>> it sends like this "hellohow_are_you" , but it is wrong , how can i >>> solve it ? >>> >>> >>> >>> thanks in advance >>> >>> >> >> > >
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Venkat |
last post by:
Hi,
My HTML page doesnot work properly in Netscape 7.1. But works fine
in Opera 7 and IE 6.0. I could not figure out the problem. If any one
could/suggest it would be nice.. This piece of HTML...
|
by: Sathesh Arumugam |
last post by:
Client is sending data a,b,c using seperate send method to the server
eg.,
Socket.Send('a')
Socket.Send('b')
Socket.Send('c')
In the Server we are using Receive method to receive the incoming...
|
by: richardshen |
last post by:
DB2 WSE V8.1.5 on Windows 2003.
For a new database, I use Control Center to drop the UserSpace and
created a new one. Control Center not responding.
All the existing connections looks ok, but...
|
by: Hasan O |
last post by:
Hi ,
maybe it is not the right place to ask .
Hi , i have problem about sending data over socket . It waits for another
socket.send
// str = Encoding.ASCII.GetBytes("hello");
...
|
by: |
last post by:
I am trying to communicate through the socket class, but
unfortunatly I am haveing a little trouble.
The method I am trying to use:
Overloads Public Function Receive(Byte(), Integer,Integer,_...
|
by: dave |
last post by:
We have an application that works perfectly in-house (tested on 3
different servers). It uses Microsoft.Web.UI.WebControls.dll for menubars
and toolbars.
Problem Description:
We uploaded...
|
by: Arronax |
last post by:
Just a basic question after I didn't see any examples on the web other
than the "None" enum.
Is this just a way of sending "hints" to server/client, or is there
another more valuable use to...
|
by: Ryan Liu |
last post by:
Hi,
One day I really need have a good study or network, not just C#. But I am in
a hurry, can someone explain SocketFlags, is that save I use
SocketFlags.None when I call Socket.Receive()...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |