473,407 Members | 2,315 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

i have problem in C# CODE

2
i have code in C# between CLIENT and SERVER to collocates the packet lose and time delay the programming is working good in LAN 127.0.0.1 but in WAN is stopping at first PACKET LOSE it doesn’t complete to END loop,,,,,, How can i use THREAD in this code ..???

THANK YOU .....

SERVER CODE
Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Net;
  5. using System.Net.Sockets;
  6.  namespace UPDServer
  7. {    class Program
  8.     {        static void Main(string[] args)
  9.         {   int recv;
  10.    byte[] data = new byte[1024];
  11.    IPEndPoint ipep = new IPEndPoint(IPAddress.Any, 7778);
  12.    Socket newsock = new Socket(AddressFamily.InterNetwork,
  13.            SocketType.Dgram, ProtocolType.Udp);
  14.    newsock.Bind(ipep);
  15.    Console.WriteLine("Waiting for a client...");
  16.    IPEndPoint sender = new IPEndPoint(IPAddress.Any, 0);
  17.    EndPoint tmpRemote = (EndPoint)(sender);
  18.    recv = newsock.ReceiveFrom(data, ref tmpRemote);
  19.    Console.WriteLine("Message received from {0}:", tmpRemote.ToString());
  20.    Console.WriteLine(Encoding.ASCII.GetString(data, 0, recv));
  21.    string welcome = "Welcome to my test server";
  22.    data = Encoding.ASCII.GetBytes(welcome);
  23.    newsock.SendTo(data, data.Length, SocketFlags.None, tmpRemote);
  24.    for (int i = 0; i < 100; i++)
  25.    {       data = new byte[1024];
  26.        recv = newsock.ReceiveFrom(data, ref tmpRemote);
  27.        newsock.SendTo(data,data.Length, SocketFlags.None, tmpRemote);
  28.        Console.WriteLine(Encoding.ASCII.GetString(data, 0, recv));
  29.    }      
  30.    newsock.Close();
  31.    Console.ReadLine();
  32.         }
  33.     }
  34. }
CLIENT CODE
Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Net;
  5. using System.Net.Sockets;
  6.  
  7. namespace ConsoleApplication1
  8. {    class Program
  9.     {        static void Main(string[] args)
  10.         {            byte[] data = new byte[1024];
  11.             IPEndPoint ipep = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 7778);
  12.             Socket server = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
  13.             string welcome = "Hello, are you there?";
  14.             data = Encoding.ASCII.GetBytes(welcome);
  15.             server.SendTo(data, data.Length, SocketFlags.None, ipep);
  16.             IPEndPoint sender = new IPEndPoint(IPAddress.Any, 0);
  17.             EndPoint tmpRemote = (EndPoint)sender;
  18.             data = new byte[1024];
  19.             int recv = server.ReceiveFrom(data, ref tmpRemote);
  20.             Console.WriteLine("Message received from {0}:", tmpRemote.ToString());
  21.             Console.WriteLine(Encoding.ASCII.GetString(data, 0, recv));
  22.             string[] sndt = new string [100];
  23.             string[] rcvt = new string [100];
  24.             Console.WriteLine( "send time ^^" + "receive time ( m:s:ms:tt)");
  25.             data = new byte[1024];
  26.             for( int i=0 ; i<100 ; i++ )
  27.             {                // save time to sndt[] and send the packet   .ToString
  28.             sndt[i] = DateTime.Now.Minute + ":" + DateTime.Now.Second + ":" + DateTime.Now.Millisecond + ":" + DateTime.Now.Ticks.ToString();
  29.             server.SendTo( Encoding.ASCII.GetBytes ("packet NUM:" + i) , ipep);
  30.                    //recieve the packet and save the time in rcvt[]...........
  31.             recv = server.ReceiveFrom(data, ref tmpRemote );
  32.             rcvt[i] = DateTime.Now.Minute + ":" + DateTime.Now.Second + ":" + DateTime.Now.Millisecond + ":" + DateTime.Now.Ticks.ToString();
  33.             Console.WriteLine(Encoding.ASCII.GetString(data, 0, recv) + "\r=========" + i + "=========\n");
  34.             Console.WriteLine(sndt[i]);
  35.             Console.WriteLine(rcvt[i]);
  36.             }
  37.             //}
  38.  
  39.             Console.WriteLine("Stopping client");
  40.             server.Close();
  41.             Console.ReadLine();
  42.         }
  43.     }
  44. }
May 1 '10 #1
2 1543
tlhintoq
3,525 Expert 2GB
TIP: When you first created your question you were asked to wrap your code with [code] tags.

It really does help a bunch. Look how much easier it is to read now that someone has done it for you. Its the button with a '#' on it. More on tags. They're cool. Check'em out.
May 1 '10 #2
mrgmrk
2
i have code in C# between CLIENT and SERVER to collocates the packet lose and time delay the programming is working good in LAN 127.0.0.1 but in WAN is stopping at first PACKET LOSE it doesn’t complete to END loop,,,,,, How can i use THREAD in this code ..???

THANK YOU .....

Expand|Select|Wrap|Line Numbers
  1.   SERVER  CODE
  2.  using System;
  3. using System.Collections.Generic;
  4. using System.Text;
  5. using System.Net;
  6. using System.Net.Sockets;
  7.  namespace UPDServer
  8. {    class Program
  9.     {        static void Main(string[] args)
  10.         {   int recv;
  11.    byte[] data = new byte[1024];
  12.    IPEndPoint ipep = new IPEndPoint(IPAddress.Any, 7778);
  13.    Socket newsock = new Socket(AddressFamily.InterNetwork,
  14.            SocketType.Dgram, ProtocolType.Udp);
  15.    newsock.Bind(ipep);
  16.    Console.WriteLine("Waiting for a client...");
  17.    IPEndPoint sender = new IPEndPoint(IPAddress.Any, 0);
  18.    EndPoint tmpRemote = (EndPoint)(sender);
  19.    recv = newsock.ReceiveFrom(data, ref tmpRemote);
  20.    Console.WriteLine("Message received from {0}:", tmpRemote.ToString());
  21.    Console.WriteLine(Encoding.ASCII.GetString(data, 0, recv));
  22.    string welcome = "Welcome to my test server";
  23.    data = Encoding.ASCII.GetBytes(welcome);
  24.    newsock.SendTo(data, data.Length, SocketFlags.None, tmpRemote);
  25.    for (int i = 0; i < 100; i++)
  26.    {       data = new byte[1024];
  27.        recv = newsock.ReceiveFrom(data, ref tmpRemote);
  28.        newsock.SendTo(data,data.Length, SocketFlags.None, tmpRemote);
  29.        Console.WriteLine(Encoding.ASCII.GetString(data, 0, recv));
  30.    }      
  31.    newsock.Close();
  32.    Console.ReadLine();
  33.         }
  34.     }
  35. }
  36.  
  37. CLIENT  CODE
  38. using System;
  39. using System.Collections.Generic;
  40. using System.Text;
  41. using System.Net;
  42. using System.Net.Sockets;
  43.  
  44. namespace ConsoleApplication1
  45. {    class Program
  46.     {        static void Main(string[] args)
  47.         {            byte[] data = new byte[1024];
  48.             IPEndPoint ipep = new IPEndPoint(IPAddress.Parse("127.0.0.1"), 7778);
  49.             Socket server = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
  50.             string welcome = "Hello, are you there?";
  51.             data = Encoding.ASCII.GetBytes(welcome);
  52.             server.SendTo(data, data.Length, SocketFlags.None, ipep);
  53.             IPEndPoint sender = new IPEndPoint(IPAddress.Any, 0);
  54.             EndPoint tmpRemote = (EndPoint)sender;
  55.             data = new byte[1024];
  56.             int recv = server.ReceiveFrom(data, ref tmpRemote);
  57.             Console.WriteLine("Message received from {0}:", tmpRemote.ToString());
  58.             Console.WriteLine(Encoding.ASCII.GetString(data, 0, recv));
  59.             string[] sndt = new string [100];
  60.             string[] rcvt = new string [100];
  61.             Console.WriteLine( "send time ^^" + "receive time ( m:s:ms:tt)");
  62.             data = new byte[1024];
  63.             for( int i=0 ; i<100 ; i++ )
  64.             {                // save time to sndt[] and send the packet   .ToString
  65.             sndt[i] = DateTime.Now.Minute + ":" + DateTime.Now.Second + ":" + DateTime.Now.Millisecond + ":" + DateTime.Now.Ticks.ToString();
  66.             server.SendTo( Encoding.ASCII.GetBytes ("packet NUM:" + i) , ipep);
  67.                    //recieve the packet and save the time in rcvt[]...........
  68.             recv = server.ReceiveFrom(data, ref tmpRemote );
  69.             rcvt[i] = DateTime.Now.Minute + ":" + DateTime.Now.Second + ":" + DateTime.Now.Millisecond + ":" + DateTime.Now.Ticks.ToString();
  70.             Console.WriteLine(Encoding.ASCII.GetString(data, 0, recv) + "\r=========" + i + "=========\n");
  71.             Console.WriteLine(sndt[i]);
  72.             Console.WriteLine(rcvt[i]);
  73.             }
  74.  
  75.  
  76.  
  77.             //}
  78.  
  79.  
  80.  
  81.  
  82.  
  83.             Console.WriteLine("Stopping client");
  84.             server.Close();
  85.             Console.ReadLine();
  86.  
  87.  
  88.         }
  89.     }
  90. }
  91.  
May 1 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: geod | last post by:
Here's the code in question. Even as the only div in a page, mozilla e al will render this as 100%. I tried removing the background image removing padding, doing ANYTHING -- even hard-coding the...
0
by: Stephen | last post by:
I was wondering if someone could please help me with an array I'd like to create in an asp.net page. I have to design an array which stores the values of addresses manually entered into textboxes...
9
by: Harshit | last post by:
I am working on socket programming, encountered a new and strange problem today. I am using #define PORT 80, before main(), and I am calling PORT in one of the statments inside main(), I get an...
7
by: Franck Diastein | last post by:
Hi, when I call ExportData I have this error: Invalid attempt to Read when reader is closed. Telling me that there's a problem with this line: while(_dataR.Read()){ Code:...
0
by: Michael Chong | last post by:
I am not very good in C++ problem and this is my codes below. I do not know whether I got handshaking involve in my code. Could you guys let me know? HANDLE OpenComm(char *lpszPort, int nBaud,...
1
by: Horny LaBelle | last post by:
The following style sheet for creating drop caps works fine in Safari, Opera, Omniweb and Explorer, the drop caps extend over 3 lines. Only in Firefox it doesn't look as it should, they extend over...
5
by: jbenner | last post by:
I have opened a PMR for this with IBM, and am not asking for advice from the DB2 DBA community. I am posting this as an FYI that DB2 Health Monitor, even at the latest version of DB2, still can cause...
2
by: Shriphani | last post by:
Hi, I was trying to solve the sumtrian problem in the SPOJ problem set ( https://www.spoj.pl/problems/SUMTRIAN/ ) and this is the solution I submitted: http://pastebin.ca/1035867 The result...
8
by: Aftabpasha | last post by:
I have seen a simple program for handling Link List operations. The following is the part of the code that contains the problem. The code is modified but contains all necessary information regarding...
2
by: RomeoX | last post by:
Hi there, I have created a free website at Xtreemhost site. They are saying that they support Send email in the free hosting. Anyway I tried to set a page "Contact Us" and I want the visitor when...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
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...
0
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...
0
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
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
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...

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.