473,657 Members | 2,450 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How can I call this?

How can I call this?
This doesn't work:
SendReceiveTest 4();

public static int SendReceiveTest 4(Socket server)
{
byte[] msg = Encoding.UTF8.G etBytes("This is a test");
byte[] bytes = new byte[256];
try
{
// Blocks until send returns.
int i = server.Send(msg , 0, msg.Length, SocketFlags.Non e);
Console.WriteLi ne("Sent {0} bytes.", i);

// Get reply from the server.
server.Receive( bytes, 0, server.Availabl e, SocketFlags.Non e);
Console.WriteLi ne(Encoding.UTF 8.GetString(byt es));
}
catch (SocketExceptio n e)
{
Console.WriteLi ne("{0} Error code: {1}.", e.Message,
e.ErrorCode);
return (e.ErrorCode);
}
return 0;
}

Thanks,
Trint

Nov 16 '05 #1
2 2454
Hi,

You have to pass the Socet -
Socket mySocket = new Socket (...);
int retValue = SendReceiveTest 4(mySocket);

--
Regards,
Peter Jausovec
(http://blog.jausovec.net)
"trint" <tr***********@ gmail.com> je napisal v sporocilo
news:11******** *************@l 41g2000cwc.goog legroups.com ...
How can I call this?
This doesn't work:
SendReceiveTest 4();

public static int SendReceiveTest 4(Socket server)
{
byte[] msg = Encoding.UTF8.G etBytes("This is a test");
byte[] bytes = new byte[256];
try
{
// Blocks until send returns.
int i = server.Send(msg , 0, msg.Length, SocketFlags.Non e);
Console.WriteLi ne("Sent {0} bytes.", i);

// Get reply from the server.
server.Receive( bytes, 0, server.Availabl e, SocketFlags.Non e);
Console.WriteLi ne(Encoding.UTF 8.GetString(byt es));
}
catch (SocketExceptio n e)
{
Console.WriteLi ne("{0} Error code: {1}.", e.Message,
e.ErrorCode);
return (e.ErrorCode);
}
return 0;
}

Thanks,
Trint

Nov 16 '05 #2
Peter,
Socket mySocket = new Socket (System.IntPtr. Zero);<<here
What do I put here (...)?
I get some type of error code no matter what I put:
"CS0122: 'System.Net.Soc kets.Socket.Soc ket(System.IntP tr)' is
inaccessible due to its protection level."

Here is my code before that:
private void button12_Click( object sender, System.EventArg s e)
{
IPHostEntry ipHostInfo = Dns.Resolve("NP IFA21AE");
IPAddress ipAddress = ipHostInfo.Addr essList[0];
IPEndPoint ipe = new IPEndPoint(ipAd dress,515);
TcpClient s = new TcpClient();
//IPAddress Send = ipHostInfo.Addr essList[0];

try
{
s.Connect(ipe);
}
catch(ArgumentN ullException ae)
{
Console.WriteLi ne("ArgumentNul lException : {0}", ae.ToString());
// listBox1.Items. Add("ArgumentNu llException : {0}", ae.ToString());
}
catch(SocketExc eption se)
{
Console.WriteLi ne("SocketExcep tion : {0}", se.ToString());
// listBox1.Items. Add("SocketExce ption : {0}", se.ToString());
}
catch(Exception se)
{
Console.WriteLi ne("Unexpected exception : {0}", e.ToString());
// listBox1.Items. Add("Unexpected exception : {0}", e.ToString());
}
//
// byte[] msg = System.Text.Enc oding.ASCII.Get Bytes("This is a test");
// int bytesSent = s.Send(msg);
//
// byte[] bytes = new byte[1024];
// int bytesRec = s.Receive(bytes );
// Console.WriteLi ne("Echoed text = {0}",
// System.Text.Enc oding.ASCII.Get String(bytes, 0, bytesRec));

Socket mySocket = new Socket (System.IntPtr. Zero);
int retValue = SendReceiveTest 4(mySocket);
}
Thanks for any help,
Trint
.Net programmer
tr***********@g mail.com

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #3

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

Similar topics

5
1921
by: Mario Thiel | last post by:
Hello, i am new to JavaScript and right now i am learning Call by Value. i tryed to write a small script but somehow it doesnt work right. i cant put <br> into it, and i can only put the document.write(xyz,x) in the function. <html> <head> <script language="JavaScript">
1
3391
by: Marwan | last post by:
Hello I am using asynchronous delegates to make a call to a COM ActiveX object, but even though the call occurs on a separate thread, my UI is still blocking. If i put the thread to sleep in my delegate call, the application is well behaved (no UI freeze), but the call to the com object causes the UI to lock up Do I have to manage calls to an ActiveX object differently than using the BeginInvoke and a callback A sample of the code I...
3
2364
by: Vinodh Kumar P | last post by:
What is call stack? I am sorry if its perceived as an off topic.
15
2118
by: Steve Jorgensen | last post by:
I'm looking for coding style opinions. It looks to me like most VB/VBA coders use the command-style syntax for calling subs or functions being treated as subs in a particular context ... Foo "ABC", varDest Occasionally, I see code using the Call syntax instead. Call Foo("ABC", varDest)
35
10771
by: hasho | last post by:
Why is "call by address" faster than "call by value"?
7
6950
by: rahul8143 | last post by:
hello, what is difference between system call and library function call? Does library function call can have context switch to kernel mode? regards, rahul
7
6800
by: archana | last post by:
Hi all, I am having application in which i am doing asynchronous call.I am using manualresetevent to wait for asynchronous call to complete. I want to stop asynchronous call after certain period of time. I want something like thread.abort for aborting aynchronous call. Can someone tell me way of aborting asynchronous call.
24
6571
by: John | last post by:
I know this is a very fundamental question. I am still quite confused if the program call stack stack should always grows upwards from the bottom, or the opposite, or doesn't matter?? That means the stack pointer should go upwards when there are "push" operations, and stack pointer should go downards when there are "pop" operations?? If this is the case, the address should go upwards (increasing) or downards (decreasing) then? i.e....
3
1812
by: xtrigger303 | last post by:
Hi to all, a newbie question. Is it possible to avoid the virtual mechanism with pointers to members syntax the same way it's done with an explicit call ( obj.Base::Func() )? It would be useful for something I'm doing... check out the trivial program down here... Thanks in advance, Francesco #include <iostream>
275
12247
by: Astley Le Jasper | last post by:
Sorry for the numpty question ... How do you find the reference name of an object? So if i have this bob = modulename.objectname() how do i find that the name is 'bob'
0
8421
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8844
Oralloy
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8742
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8518
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7354
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5643
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4330
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2743
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 we have to send another system
2
1971
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.