473,499 Members | 1,618 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

C# Net Sockets multiple transactions problem, with source.

Ted
Hello all,

Please could somebody with a little time on their
hands help me with my net sockets program?

The aim is to send multiple transactions via C#
network stream and read them back. The source
is designed to send a 50byte header and read
the result (50bytes). For one run this is fine,
however since i'll be using multiple transactions
i set it up with a windowsform button so i can
test sending the same transaction as many times
as i'd like, and hopefully get the same result.

However, when sending the second transaction (the
same as the first), it fails. I'm not sure if
this is my CICS driver refusing the second
transaction because i sent the same transaction
twice, or my program? Hopefully the former, although
I'm sure I made some test code previously that
worked fine and proved otherwise.

Could someone take a look for me and provide some
advice on the network stream. Most of the code
in this program is borrowed and tailored for my
purposes, if it comes in handy for anyone else
trying a similar thing then cool, but dont thank
me etc.

If you do a search for 'screwing' in the code
you'll find the bit where it fails and catches
an exception. Note i've only been programming in
C# for a week or so, so not entirely sure how
to trace through yet.

Here's the code..
www.amusement-arcade.com/netsock.cs

The code should be compilable, although you'll
need an IP address to connect to, and that's
behind a company firewall, so no good to
yourself, hence, i've hidden it and the port
as x.x.x.x etc..

Best regards,
Jode
Please reply to andrewsj@**removethisspambit**uk.ibm.com
if not in this post.
Nov 15 '05 #1
6 4220
Not totally sure as have not tried to run the code as would need to build a
server to send to,etc. However, I you are creating the stream (using
GetStream) on each call to the method. I wonder if after it goes out of
scope the first time, if that is not part of your problem. Try creating a
private form Stream var (like your tcpclient var) and assign it once and use
the stream from then on until you close the stream and tcpclient. Failing
that, I would remove cics from the diag picture and setup tcpListener server
to test against. You could also post the Exception message your getting
(catch and display it) to help us with a little more info. hth

--
William Stacey, MS MVP

"Ted" <go****@gerbil.u-net.com> wrote in message
news:bb**************************@posting.google.c om...
Hello all,

Please could somebody with a little time on their
hands help me with my net sockets program?

The aim is to send multiple transactions via C#
network stream and read them back. The source
is designed to send a 50byte header and read
the result (50bytes). For one run this is fine,
however since i'll be using multiple transactions
i set it up with a windowsform button so i can
test sending the same transaction as many times
as i'd like, and hopefully get the same result.

However, when sending the second transaction (the
same as the first), it fails. I'm not sure if
this is my CICS driver refusing the second
transaction because i sent the same transaction
twice, or my program? Hopefully the former, although
I'm sure I made some test code previously that
worked fine and proved otherwise.

Could someone take a look for me and provide some
advice on the network stream. Most of the code
in this program is borrowed and tailored for my
purposes, if it comes in handy for anyone else
trying a similar thing then cool, but dont thank
me etc.

If you do a search for 'screwing' in the code
you'll find the bit where it fails and catches
an exception. Note i've only been programming in
C# for a week or so, so not entirely sure how
to trace through yet.

Here's the code..
www.amusement-arcade.com/netsock.cs

The code should be compilable, although you'll
need an IP address to connect to, and that's
behind a company firewall, so no good to
yourself, hence, i've hidden it and the port
as x.x.x.x etc..

Best regards,
Jode
Please reply to andrewsj@**removethisspambit**uk.ibm.com
if not in this post.

Nov 15 '05 #2
Ted
If I catch the exceptions and display the messages then
the output looks like this (after three runs)..

::Connecting to RS4
::Connected to x.x.x.x:xxxx
::Sending Transaction : SDTC,TEST SDI FROM MY CODE ,IC,
--SDTC started SD on CICS SYSID PRE8.
::Sending Transaction : SDTC,TEST SDI FROM MY CODE ,IC,
Unable to write data to the transport connection.
::Sending Transaction : SDTC,TEST SDI FROM MY CODE ,IC,
Operation not allowed on non-connected sockets.
Nov 15 '05 #3
Ted
Thanks William, i thought that too, but i couldnt' work
out how to only create the stream once and for it to
still have visibility to sendTransaction.

Defining it as..

public class WinForm : System.Windows.Forms.Form
{
TcpClient sdiClient = new TcpClient();
Stream networkStream = sdiClient.GetStream();

Fails as 'WinForm.sdiClient denotes a field where a class is expected'.

Which is fair enough I guess, could you let me know how
I should define it?

Regards, Jode
Nov 15 '05 #4
I spotted one problem in the code. This may or may not be the real problem
here but I think you should fix it anyway. The problem is on this line:

int k=networkStream.Read(returnedOutput,0,returnedOutp ut.Length);

You are attempting to read returnedOutput.Length bytes from the network
buffer. Due to the nature of TCP streaming the call might return anything
between 1 to returnedOutput.Length bytes.

To fix the problem, call networkStream.Read in a loop until you have
received all the data.

Sami
www.capehill.net
Nov 15 '05 #5
// Private field declarations, visible in all instance methods.
private TcpClient sdiClient;
private Stream networkStream;

public MyClass() //Constructor.
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

sdiClient = new TcpClient();
networkStream = sdiClient.GetStream();
}

As a side note, you may not want to bind your network logic so closely to
your form. Another option would be to create another class that encapulates
the your network logic and the TcpClient and stream in a seperate network
class. You may then have Send and Receive methods on it (et al.) This may
make it easier to share this code with other forms and/or classes (even
console versions of your program.) Also, Sami was right on with the Read
method. You need to loop on receive. Many examples of this in the Help.
hth

--
William Stacey, MVP

"Ted" <go****@gerbil.u-net.com> wrote in message
news:bb**************************@posting.google.c om...
Thanks William, i thought that too, but i couldnt' work
out how to only create the stream once and for it to
still have visibility to sendTransaction.

Defining it as..

public class WinForm : System.Windows.Forms.Form
{
TcpClient sdiClient = new TcpClient();
Stream networkStream = sdiClient.GetStream();

Fails as 'WinForm.sdiClient denotes a field where a class is expected'.

Which is fair enough I guess, could you let me know how
I should define it?

Regards, Jode


Nov 15 '05 #6
Ted
"Sami Vaaraniemi" <sa***************@jippii.fi> wrote in message news:<c2**********@phys-news1.kolumbus.fi>...
I spotted one problem in the code. This may or may not be the real problem
here but I think you should fix it anyway. The problem is on this line:

int k=networkStream.Read(returnedOutput,0,returnedOutp ut.Length);

You are attempting to read returnedOutput.Length bytes from the network
buffer. Due to the nature of TCP streaming the call might return anything
between 1 to returnedOutput.Length bytes.

To fix the problem, call networkStream.Read in a loop until you have
received all the data.

Sami
www.capehill.net

Hello both,

Not sure where my earlier reply went to you Sami, however, you're right
i should read it in a loop, but in this case I know that 50bytes are
on the way back to me, when i start running transactions properly the
returning reply tells me within the first 23bytes how long the stream
is anyway. I'll fix this up later

William, thanks for the tip, i've altered the code, and although it
gets further, it errors during a read (even if i attempt to read just
one byte).

The source is www.amusement-arcade.com/netsock.cs
and the output is www.amusement-arcade.com/output.jpg

It looks like i'll have to set up a host and see whatsa goin on, unless
you can spot something else.

Regards, Jode
Nov 15 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

16
7444
by: noah | last post by:
Does PHP have a feature to associate Cookie sessions with a persistent database connection that will allow a single transaction across multiple HTTP requests? Here is how I imagine my process: I...
11
8942
by: Alban Hertroys | last post by:
Oh no! It's me and transactions again :) I'm not really sure whether this is a limitation of psycopg or postgresql. When I use multiple cursors in a transaction, the records inserted at the...
6
2566
by: Christopher J. Bottaro | last post by:
Hi, Why is there no support for explicit transactions in the DB API? I mean like transaction() to start the trans and commit() and rollback() would end the trans or something. The reason why I...
6
4957
by: James Radke | last post by:
Hello, I have a multithreaded windows NT service application (vb.net 2003) that I am working on (my first one), which reads a message queue and creates multiple threads to perform the processing...
15
2160
by: mrpolitics | last post by:
So I'm working with PureIRCD (http://sourceforge.net/projects/pure-ircd) and everything was fine untill yesterday when the server crashed. So I did a cold restart and staretd the server back up...
4
2232
by: Robert McNally | last post by:
Hello, I'm currently learning c# and have been trying to write a simple program with sockets. The problem is i'm trying to send an email with an attachment, (which is the program itself) by...
0
1423
by: rossabri | last post by:
This topic has been addressed in limited detail in other threads: "sockets don't play nice with new style classes :(" May 14 2005....
1
2177
by: crawfordr | last post by:
Hello, I have created a perl script that connects to a specific socket (Ip address/port) using protocall of TCP. It is the server socket script. There is also coding to manage multiple handles by...
0
1592
by: crawfordr | last post by:
Hello, I have created a perl script that connects to a specific socket (Ip address/port) using protocall of TCP. It is the server socket script. There is also coding to manage multiple handles by...
0
7132
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7009
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7223
jinu1996
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...
0
7390
tracyyun
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...
0
4602
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3094
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1427
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
665
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
302
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.