Search Results

Search found 21 results on 1 pages for 'udpclient'.

Page 1/1 | 1 

  • Use UdpClient with IPv4 and IPv6?

    - by mazzzzz
    A little while ago I created a class to deal with my LAN networking programs. I recently upgraded one of my laptops to windows 7 and relized that windows 7 (or at least the way I have it set up) only supports IPv6, but my desktop is still back in the Windows xp days, and only uses IPv4. The class I created uses the UdpClient class, and is currently setup to only work with IPv4.. Is there a way to modify my code to allow sending and receiving of IPv6 and IPv4 packets?? It would be hard to scrap the classes code, a lot of my programs rely on this class. I would like to keep the class as close to its original state, so I don't need to modify my older programs, only switch out the old class for the updated one. Thanks for any and all help, Max Send: using System.Net.Sockets;UdpClient tub = new UdpClient (); tub.Connect ( new IPEndPoint ( ToIP, ToPort ) ); UdpState s = new UdpState (); s.client = tub; s.endpoint = new IPEndPoint ( ToIP, ToPort ); tub.BeginSend ( data, data.Length, new AsyncCallback ( SendCallBack ),s); private void SendCallBack ( IAsyncResult result ) { UdpClient client = (UdpClient)( (UdpState)( result.AsyncState ) ).client; IPEndPoint endpoint = (IPEndPoint)( (UdpState)( result.AsyncState ) ).endpoint; client.EndSend ( result ); } Receive: UdpClient tub = new UdpClient (ReceivePort); UdpState s = new UdpState (); s.client = tub; s.endpoint = new IPEndPoint ( ReceiveIP, ReceivePort ); s.callback = cb; tub.BeginReceive ( new AsyncCallback ( receivedPacket ), s ); public void receivedPacket (IAsyncResult result) { UdpClient client = (UdpClient)( (UdpState)( result.AsyncState ) ).client; IPEndPoint endpoint = (IPEndPoint)( (UdpState)( result.AsyncState ) ).endpoint; Byte[] receiveBytes = client.EndReceive ( result, ref endpoint ); ReceivedPacket = new Packet ( receiveBytes ); client.Close(); //Do what ever with the packets now }

    Read the article

  • UdpClient receiving and sending at the same time

    - by SoMoS
    Hello, I am maintaining other's code and its using the class UdpClient. The code declares one instance of UdpClient and receives data continuosly using the UdpClient.Receive(). When data is received it is processed in another thread and the UdpClient calls Receive() again. At the same time when the data is processed the same client is sending a response back. Question: Is this a bug? I think so because UdpClient is not thread safe so you can not call two methods at the same time. Anyways code is working fine but ...

    Read the article

  • How to set ReceiveBufferSize for UDPClient? or Does it make sense to set? C#

    - by Jack
    Hello all. I am implementing a UDP data transfer thing. I have several questions about UDP buffer. I am using UDPClient to do the UDP send / receive. and my broadband bandwidth is 150KB/s (bytes/s, not bps). I send out a 500B datagram out to 27 hosts 27 hosts send back 10KB datagram back if they receive. So, I should receive 27 responses, right? however, I only get averagely 8 - 12 instead. I then tried to reduce the size of the response down to 500B, yes, I receive all. A thought of mine is that if all 27 hosts send back 10KB response at almost same time, the incoming traffic will be 270KB/s (likely), that exceeds my incoming bandwidth so loss happens. Am I right? But I think even if the incoming traffic exceeds the bandwidth, is the Windows supposed to put the datagram in the buffer and wait for receive? I then suspect that maybe the ReceiveBufferSize of my UdpClient is too small? by default, it is 8092B?? I don't know whether I am all right at these points. Please give me some help.

    Read the article

  • Respond to a UDP message

    - by JDCAce
    I have a pair of very simple C# programs (server and client). The client's user enters an IP address, and the client sends a UDP message to the server. The server uses UDPClient.Receive() to listen to IPAddress.Any, prints out the message it received and where it was sent from (the client's IP address), then sends a UDP message back to the client. The problem is in that last part: my client is not receiving any message. It listens only to the server, instead of IPAddress.Any. The SendUdpMessage() and WaitForMessage() methods are identical, except for the IPAddress.Any part. I cannot find what's wrong! I can post the code if I need to, but I don't know which part is relevant, and I don't want to post the entire program (about 150 lines combined).

    Read the article

  • How to do UDP without port forwarding

    - by igor
    Hi all, I am creating an application in C#, It should send data with UDP. Everything works fine until, I try to communicate with a PC that is on the internet behind a router. How do I fix this so that I can use UDP without port forwarding?

    Read the article

  • How can we avoid packet missing in UDP Flex?

    - by Naveen kumar
    Hi all, I'm trying to send large files using UDP Adobe air to CPP. While transferring large files some packets are missing. How can I retrieve the missing packets data? I'm first of all connecting client(air) with server(cpp) using tcp. After connection establishment I'm starting file transfer. I am planning to get the file missing data using tcp and then resending the missing packets using tcp. Can anybody tell me how can i come to know which packets are missing while transferring. Thank you.

    Read the article

  • When is it useful to define your own delegates instead of using the generics?

    - by Carlos
    I've been going through some old code, where I came across some custom defined delegates, which are used thus: private delegate void ListenDelegate(UdpClient listener, bool multicast); private void ListenOn(UdpClient listener, bool multicast) { new ListenDelegate(_ListenLoop).BeginInvoke(listener, multicast, null, null); } With some of the new .NET framework versions, you can do the following: private void ListenOn(UdpClient listener, bool multicast) { new Action<UdpClient, bool>(_ListenLoop).BeginInvoke(listener, multicast, null, null); } This ought to be exactly the same. Is there any point in defining your own delegates, when the generic delegates seem to do the same job with less space? Or have I missed something about the generics that makes them not equivalent?

    Read the article

  • Receiving broadcast messages

    - by Prasad
    Hi, I'm trying to receive broadcast messages using C# code in an ISDN network with BRI interface at my end. I see the packets sent to the broadcast ip address (239.255.255.255) on some ports using Comm View tool. But when I try to listen to this IP address, it says the address is not in a valid context. But when I send broadcast messages to 255.255.255.255 on a port, I can receive those messages with the below code.. What could be the problem with this ip address - 239.255.255.255 ? The code I use to listen to broadcast messages is.. UdpClient udp = new UdpClient(); IPEndPoint receiveEndPoint = new IPEndPoint(IPAddress.Any, 8013); // If I use IPAddress.Parse("239.255.255.255") to listen to, // it says "the address is not in a valid // context." udp.Client.Bind(receiveEndPoint); udp.BeginReceive(_Callback, udp); static private void _Callback(IAsyncResult iar) { try { UdpClient client = (UdpClient)iar.AsyncState; client.BeginReceive(_Callback, client); IPEndPoint ipRemote = new IPEndPoint(IPAddress.Any, 8013); byte[] rgb = client.EndReceive(iar, ref ipRemote); Console.WriteLine("Received {0} bytes: \"{1}\"", rgb.Length.ToString(), Encoding.UTF8.GetString(rgb)); } catch (ObjectDisposedException) { Console.WriteLine("closing listening socket"); } catch (Exception exc) { Console.WriteLine("Listening socket error: \"" + exc.Message + "\""); } } There are packets sent to the broadcast ipaddress (239.255.255.255) which I can see in Commview tool, but can't receive them from the code... Can anybody help me out please? Thanking you in advance, Prasad Kancharla.

    Read the article

  • Testing Broadcasting and receiving messages

    - by Avik
    Guys am having some difficulty figuring this out: I am trying to test whether the code(in c#) to broadcast a message and receiving the message works: The code to send the datagram(in this case its the hostname) is: public partial class Form1 : Form { String hostName; byte[] hostBuffer = new byte[1024]; public Form1() { InitializeComponent(); StartNotification(); } public void StartNotification() { IPEndPoint notifyIP = new IPEndPoint(IPAddress.Broadcast, 6000); hostName = Dns.GetHostName(); hostBuffer = Encoding.ASCII.GetBytes(hostName); UdpClient newUdpClient = new UdpClient(); newUdpClient.Send(hostBuffer, hostBuffer.Length, notifyIP); } } And the code to receive the datagram is: public partial class Form1 : Form { byte[] receivedNotification = new byte[1024]; String notificationReceived; StringBuilder listBox; UdpClient udpServer; IPEndPoint remoteEndPoint; public Form1() { InitializeComponent(); udpServer = new UdpClient(new IPEndPoint(IPAddress.Any, 1234)); remoteEndPoint=null; startUdpListener1(); } public void startUdpListener1() { receivedNotification = udpServer.Receive(ref remoteEndPoint); notificationReceived = Encoding.ASCII.GetString(receivedNotification); listBox = new StringBuilder(this.listBox1.Text); listBox.AppendLine(notificationReceived); this.listBox1.Items.Add(listBox.ToString()); } } For the reception of the code I have a form that has only a listbox(listBox1). The problem here is that when i execute the code to receive, the program runs but the form isnt visible. However when I comment the function call( startUdpListener1() ), the purpose isnt served but the form is visible. Whats going wrong?

    Read the article

  • How can I set the buffer size for the underneath Socket UDP? C#

    - by Jack
    Hi all As we know for UDP receive, we use Socket.ReceiveFrom or UdpClient.receive Socket.ReceiveFrom accept a byte array from you to put the udp data in. UdpClient.receive returns directly a byte array where the data is My question is that How to set the buffer size inside Socket. I think the OS maintains its own buffer for receive UDP data, right? for e.g., if a udp packet is sent to my machine, the OS will put it to a buffer and wait us to Socket.ReceiveFrom or UdpClient.receive, right? How can I change the size of that internal buffer? I have tried Socket.ReceiveBuffSize, it has no effect at all for UDP, and it clearly said that it is for TCP window. Also I have done a lot of experiments which proves Socket.ReceiveBufferSize is NOT for UDP. Can anyone share some insights for UDP internal buffer??? Thanks

    Read the article

  • C# UDP Socket taking time to send data to unknown IP

    - by Mohsan
    Hi. i am sending data to UDP socket using this code Socket udpClient = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); IPEndPoint ipEndPoint = new IPEndPoint(IPAddress.Parse(obj.destAddress), obj.destPort); byte[] buf = new byte[obj.length]; Array.Copy((byte[])obj.data, buf, obj.length); int n = udpClient.SendTo(buf, ipEndPoint); udpClient.Close(); this code works fine when IP exists in current network, but it takes 3-5 seconds when I send data to unknown IP address. This causes main application to hang for 3-5 seconds.. What could be the reason behind this problem..

    Read the article

  • UDP Tracker not responding

    - by kelton52
    Alright, so I'm trying to connect to UDP trackers using c#, but I never get a response. I also don't get any errors. Here's my code. namespace UDPTester { class MainClass { public static bool messageReceived = false; public static Random Random = new Random(); public static void LOG(string format, params object[] args) { Console.WriteLine (format,args); } public static void Main (string[] args) { LOG ("Creating Packet..."); byte[] packet; using(var stream = new MemoryStream()) { var bc = new MiscUtil.Conversion.BigEndianBitConverter(); using(var br = new MiscUtil.IO.EndianBinaryWriter(bc,stream)) { LOG ("Magic Num: {0}",(Int64)0x41727101980); br.Write (0x41727101980); br.Write((Int32)0); br.Write ((Int32)Random.Next()); packet = stream.ToArray(); LOG ("Packet Size: {0}",packet.Length); } } LOG ("Connecting to tracker..."); var client = new System.Net.Sockets.UdpClient("tracker.openbittorrent.com",80); UdpState s = new UdpState(); s.e = client.Client.RemoteEndPoint; s.u = client; StartReceiving(s); LOG ("Sending Packet..."); client.Send(packet,packet.Length); while(!messageReceived) { Thread.Sleep(1000); } LOG ("Ended"); } public static void StartReceiving(UdpState state) { state.u.BeginReceive(ReceiveCallback,state); } public static void ReceiveCallback(IAsyncResult ar) { UdpClient u = (UdpClient)((UdpState)(ar.AsyncState)).u; IPEndPoint e = (IPEndPoint)((UdpState)(ar.AsyncState)).e; Byte[] receiveBytes = u.EndReceive(ar, ref e); string receiveString = Encoding.ASCII.GetString(receiveBytes); LOG("Received: {0}", receiveString); messageReceived = true; StartReceiving((UdpState)ar.AsyncState); } } public class UdpState { public UdpClient u; public EndPoint e; } } I was using a normal BinaryWriter, but that didn't work, and I read somewhere that it wants it's data in BigEndian. This doesn't work for any of the UDP trackers I've found, any ideas why I'm not getting a response? Did they maybe change the protocol and not tell anyone? HTTP trackers all work fine. Trackers I've tried udp://tracker.publicbt.com:80 udp://tracker.ccc.de:80 udp://tracker.istole.it:80 Also, I'm not interested in using MonoTorrent(and when I was using it, the UDP didn't work anyways). Protocol Sources http://xbtt.sourceforge.net/udp_tracker_protocol.html http://www.rasterbar.com/products/libtorrent/udp_tracker_protocol.html

    Read the article

  • Why I can't get all UDP packets?

    - by Jack
    My program use UdpClient to try to receive 27 responses from 27 hosts. The size of the response is 10KB. My broadband incoming bandwidth is 150KB/s. The 27 responses are sent from the hosts almost at the same time and for every 10 secs. However, I can only receive 8 - 17 responses each time. The number of responses that I can receive is quite dynamic but within the range. Can anyone tell me why? why can't I receive all? I understand UDP is not reliable. but I tried receiving 5 - 10 responses at the same time, it worked. I guess the network links are not so bad. The code is very simple. ON the 27 hosts, I just use UdpClient to send 10KB to my machine. On my machine, I have one UdpClient receive datagrams. Each time I get a data, I create a thread to handle it (basically handling it means just print out "I received 10KB", but it runs in a thread). listener = new UDPListener(Port); listener.Start(); while (true) { try { UDPContext context = listener.Accept(); ThreadPool.QueueUserWorkItem(new WaitCallback(HandleMessage), context); } catch (Exception) { } } If I reduce the size of the response down to 3KB, the case gets much better that roughly 25 responses can be received. Any more idea? UDP buffer problems???

    Read the article

  • Bidirectional/Loopback UDP in .net

    - by Jason Williams
    I've got an app that needs to transmit and receive on the same port. This can happen in two cases: Where the PC is talking to a piece of remote hardware. It "replies to sender", so the datagrams come back in to my PC via the sending port. Where the PC is talking to itself (loopback mode) for testing and demoing (a test app feeds fake data into our main app via UDP). This only seems to fail when trying to achieve loopback. The only way I can get it working is to ensure that the receiver is set up first - something I cannot guarantee. Can anyone help narrow down my search by suggesting a "correct" way to implement the UdpClient(s) to handle the above situations reliably? (The only solution that I've found to work reliably with the remote hardware is to use a single UdpClient in a bidirectional manner, although I'm working with legacy code that may be influencing that finding. I've tried using two UdpClients, but they step on each others toes - In some cases, once one client is started up, the other client cannot connect. With ExclusiveAddressUse/ReuseAddress set up to allow port sharing, I can almost get it to work, apart from the receiver having to start first)

    Read the article

  • Splitting up UDP packet

    - by m3n
    Heyo, I'm using UdpClient to query game servers about server name, map, number of players, etc. I've followed the guidelines on this page http://developer.valvesoftware.com/wiki/Server_queries#Source_servers and I'm getting a correct reply: I have no idea how I would go about to get each chunk of information (server name, map and the like). Any help? I'm assuming one would have to look at the reply format specified in the wiki I linked, but I don't know what to make of it. Cheers,

    Read the article

  • Implementing the transport layer for a SIP UAC

    - by Jonathan Henson
    I have a somewhat simple, but specific, question about implementing the transport layer for a SIP UAC. Do I expect the response to a request on the same socket that I sent the request on, or do I let the UDP or TCP listener pick up the response and then route it to the correct transaction from there? The RFC does not seem to say anything on the matter. It seems that especially using UDP, which is connection-less, that I should just let the listeners pick up the response, but that seems sort of counter intuitive. Particularly, I have seen plenty of UAC implementations which do not depend on having a Listener in the transport layer. Also, most implementations I have looked at do not have the UAS receiving loop responding on the socket at all. This would tend to indicate that the client should not be expecting a reply on the socket that it sent the request on. For clarification: Suppose my transport layer consists of the following elements: TCPClient (Sends Requests for a UAC via TCP) UDPClient (Sends Requests for a UAC vid UDP) TCPSever (Loop receiving Requests and dispatching to transaction layer via TCP) UDPServer (Loop receiving Requests and dispatching to transaction layer via UDP) Obviously, the *Client sends my Requests. The question is, what receives the Response? The *Client waiting on a recv or recvfrom call on the socket it used to send the request, or the *Server? Conversely, the *Server receives my requests, What sends the Response? The *Client? doesn't this break the roles of each member a bit?

    Read the article

  • TCP/IP and UDP Questions and very small application for interview

    - by Shantanu Gupta
    I am going for an interview day after tomorrow where i will be asked vaious questions related to TCP/IP and UDP. As of now i have prepared theoritical knowledge about it. But now I am looking up for gaining some practicle knowledge related to how it works in a network. What all is going in vaious .NET classes. I want to create a very small application like a chat or something that can make me all these concepts very much clear. Could you please suggest some questions related to TCP/IP that you generally ask or that you might have faced. How communication is going from server to client. Right now I am studying TcpClient, TcpListener and UdpClient Class but I want to implement all of them so as to get aware about its working. Is Chat application a Tcp/IP application ? I would appreciate your help.

    Read the article

  • Interview Questions that can be asked on TCP/IP, UDP, Socket Programming ?

    - by Shantanu Gupta
    I am going for an interview day after tomorrow where i will be asked vaious questions related to TCP/IP and UDP. As of now i have prepared theoritical knowledge about it. But now I am looking up for gaining some practicle knowledge related to how it works in a network. What all is going in vaious .NET classes. I want to create a very small application like a chat or something that can make me all these concepts very much clear. Could you please suggest some questions related to TCP/IP that you generally ask or that you might have faced. How communication is going from server to client. Right now I am studying TcpClient, TcpListener and UdpClient Class but I want to implement all of them so as to get aware about its working. Is Chat application a Tcp/IP application ? I would appreciate your help.

    Read the article

  • Problem in udp socket programing in c

    - by Md. Talha
    I complile the following C code of UDP client after I run './udpclient localhost 9191' in terminal.I put "Enter Text= " as Hello, but it is showing error in sendto as below: Enter text: hello hello : error in sendto()guest-1SDRJ2@md-K42F:~/Desktop$ " Note: I open 1st the server port as below in other terminal ./server 9191. I beleive there is no error in server code. The udp client is not passing message to server. If I don't use thread , the message is passing .But I have to do it by thread. UDP client Code: /* simple UDP echo client */ #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <netdb.h> #include <stdio.h> #include <pthread.h> #define STRLEN 1024 static void *readdata(void *); static void *writedata(void *); int sockfd, n, slen; struct sockaddr_in servaddr; char sendline[STRLEN], recvline[STRLEN]; int main(int argc, char *argv[]) { pthread_t readid,writeid; struct sockaddr_in servaddr; struct hostent *h; if(argc != 3) { printf("Usage: %s <proxy server ip> <port>\n", argv[0]); exit(0); } /* create hostent structure from user entered host name*/ if ( (h = gethostbyname(argv[1])) == NULL) { printf("\n%s: error in gethostbyname()", argv[0]); exit(0); } /* create server address structure */ bzero(&servaddr, sizeof(servaddr)); /* initialize it */ servaddr.sin_family = AF_INET; memcpy((char *) &servaddr.sin_addr.s_addr, h->h_addr_list[0], h->h_length); servaddr.sin_port = htons(atoi(argv[2])); /* get the port number from argv[2]*/ /* create a UDP socket: SOCK_DGRAM */ if ( (sockfd = socket(AF_INET,SOCK_DGRAM, 0)) < 0) { printf("\n%s: error in socket()", argv[0]); exit(0); } pthread_create(&readid,NULL,&readdata,NULL); pthread_create(&writeid,NULL,&writedata,NULL); while(1) { }; close(sockfd); } static void * writedata(void *arg) { /* get user input */ printf("\nEnter text: "); do { if (fgets(sendline, STRLEN, stdin) == NULL) { printf("\n%s: error in fgets()"); exit(0); } /* send a text */ if (sendto(sockfd, sendline, sizeof(sendline), 0, (struct sockaddr *) &servaddr, sizeof(servaddr)) < 0) { printf("\n%s: error in sendto()"); exit(0); } }while(1); } static void * readdata(void *arg) { /* wait for echo */ slen = sizeof(servaddr); if ( (n = recvfrom(sockfd, recvline, STRLEN, 0, (struct sockaddr *) &servaddr, &slen)) < 0) { printf("\n%s: error in recvfrom()"); exit(0); } /* null terminate the string */ recvline[n] = 0; fputs(recvline, stdout); }

    Read the article

  • XmlSerializer.Deserialize blocks over NetworkStream

    - by Luca
    I'm trying to sends XML serializable objects over a network stream. I've already used this on an UDP broadcast server, where it receive UDP messages from the local network. Here a snippet of the server side: while (mServiceStopFlag == false) { if (mSocket.Available > 0) { IPEndPoint ipEndPoint = new IPEndPoint(IPAddress.Any, DiscoveryPort); byte[] bData; // Receive discovery message bData = mSocket.Receive(ref ipEndPoint); // Handle discovery message HandleDiscoveryMessage(ipEndPoint.Address, bData); ... Instead this is the client side: IPEndPoint ipEndPoint = new IPEndPoint(IPAddress.Broadcast, DiscoveryPort); MemoryStream mStream = new MemoryStream(); byte[] bData; // Create broadcast UDP server mSocket = new UdpClient(); mSocket.EnableBroadcast = true; // Create datagram data foreach (NetService s in ctx.Services) XmlHelper.SerializeClass<NetService>(mStream, s); bData = mStream.GetBuffer(); // Notify the services while (mServiceStopFlag == false) { mSocket.Send(bData, (int)mStream.Length, ipEndPoint); Thread.Sleep(DefaultServiceLatency); } It works very fine. But now i'me trying to get the same result, but on a TcpClient socket, but the using directly an XMLSerializer instance: On server side: TcpClient sSocket = k.Key; ServiceContext sContext = k.Value; Message msg = new Message(); while (sSocket.Connected == true) { if (sSocket.Available > 0) { StreamReader tr = new StreamReader(sSocket.GetStream()); msg = (Message)mXmlSerialize.Deserialize(tr); // Handle message msg = sContext.Handler(msg); // Reply with another message if (msg != null) mXmlSerialize.Serialize(sSocket.GetStream(), msg); } else Thread.Sleep(40); } And on client side: NetworkStream mSocketStream; Message rMessage; // Network stream mSocketStream = mSocket.GetStream(); // Send the message mXmlSerialize.Serialize(mSocketStream, msg); // Receive the answer rMessage = (Message)mXmlSerialize.Deserialize(mSocketStream); return (rMessage); The data is sent (Available property is greater then 0), but the method XmlSerialize.Deserialize (which should deserialize the Message class) blocks. What am I missing?

    Read the article

1