Click here to Skip to main content
15,891,935 members
Home / Discussions / C#
   

C#

 
Questionreceived data by UDP client Pin
hasan hadi7-May-15 21:43
hasan hadi7-May-15 21:43 
AnswerRe: received data by UDP client Pin
F-ES Sitecore9-May-15 2:25
professionalF-ES Sitecore9-May-15 2:25 
GeneralRe: received data by UDP client Pin
hasan hadi9-May-15 3:38
hasan hadi9-May-15 3:38 
GeneralRe: received data by UDP client Pin
F-ES Sitecore9-May-15 7:05
professionalF-ES Sitecore9-May-15 7:05 
GeneralRe: received data by UDP client Pin
hasan hadi9-May-15 7:42
hasan hadi9-May-15 7:42 
GeneralRe: received data by UDP client Pin
F-ES Sitecore9-May-15 7:48
professionalF-ES Sitecore9-May-15 7:48 
GeneralRe: received data by UDP client Pin
hasan hadi9-May-15 8:07
hasan hadi9-May-15 8:07 
AnswerRe: received data by UDP client Pin
Dr Gadgit10-May-15 5:03
Dr Gadgit10-May-15 5:03 
For sending data i use sockets a bit like this for UDP
C#
IPEndPoint IPE = new IPEndPoint(IPAddress.Parse(this.ServerIP), this.ServerPort);//Our UPD-Server address
this.Soc = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
this.Soc.Connect(IPE);
Soc.Send(this.Request, SocketFlags.None);
buffer = new byte[2048];
int Size = Soc.Receive(buffer);
this.Reply = new byte[Size];
//blur...blur
Soc.Close();

The server needs to look a bit like this
C#
IP4receiveSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
IP4receiveEndPoint = new IPEndPoint(IPAddress.Parse("0.0.0.0"), ClientPort);
IP4receiveSocket.Bind(IP4receiveEndPoint);
IPAddress IPA = IPAddress.Parse("0.0.0.0");
byte []Buf=new byte[1024];
whilst (ServiceIsRunning)
{
   EndPoint RemoteEndPoint = new IPEndPoint(IPA, 0); //Will contain the clients port 
   int RequestSize = IP4receiveSocket.ReceiveFrom(Buf, ref RemoteEndPoint);
   //Do some work like getting data from the database base on whats in the Buf message
   IP4receiveSocket.SendTo(SomeByteData, RemoteEndPoint );
}

if you are using threads to send then watchout for requests that just hanging even if you set time-outs.

You could try killing the thread using an .Abort() but this won't kill them all so the best way is to use the killing thread to call code like shown below and passing in the socket.
C#
public static void ShutMeDown(Socket Soc)
        {
            try{Soc.Shutdown(SocketShutdown.Both);} catch {;}
            try { Soc.Close(); }catch { ;}            
        }

Hope this helps
Question(solved) shorter syntax for invoking static methods in generic non-static class ? Pin
BillWoodruff7-May-15 20:41
professionalBillWoodruff7-May-15 20:41 
AnswerRe: shorter syntax for invoking static methods in generic non-static class ? Pin
Sascha Lefèvre7-May-15 22:31
professionalSascha Lefèvre7-May-15 22:31 
GeneralRe: shorter syntax for invoking static methods in generic non-static class ? Pin
BillWoodruff7-May-15 22:46
professionalBillWoodruff7-May-15 22:46 
GeneralRe: shorter syntax for invoking static methods in generic non-static class ? Pin
Sascha Lefèvre7-May-15 23:53
professionalSascha Lefèvre7-May-15 23:53 
GeneralRe: shorter syntax for invoking static methods in generic non-static class ? Pin
BillWoodruff8-May-15 0:40
professionalBillWoodruff8-May-15 0:40 
GeneralRe: shorter syntax for invoking static methods in generic non-static class ? Pin
Sascha Lefèvre8-May-15 5:27
professionalSascha Lefèvre8-May-15 5:27 
SuggestionRe: shorter syntax for invoking static methods in generic non-static class ? Pin
Richard Deeming8-May-15 0:42
mveRichard Deeming8-May-15 0:42 
Questionhow do I get datasource to put to any drive c# Pin
Member 97020587-May-15 14:19
Member 97020587-May-15 14:19 
AnswerRe: how do I get datasource to put to any drive c# Pin
Dave Kreskowiak7-May-15 16:50
mveDave Kreskowiak7-May-15 16:50 
AnswerRe: how do I get datasource to put to any drive c# Pin
OriginalGriff7-May-15 20:35
mveOriginalGriff7-May-15 20:35 
AnswerRe: how do I get datasource to put to any drive c# Pin
Richard Deeming8-May-15 0:35
mveRichard Deeming8-May-15 0:35 
QuestionHow to run a setup file in different sysytem.. Pin
Jayamanickam7-May-15 2:32
Jayamanickam7-May-15 2:32 
AnswerRe: How to run a setup file in different sysytem.. Pin
OriginalGriff7-May-15 3:10
mveOriginalGriff7-May-15 3:10 
GeneralRe: How to run a setup file in different sysytem.. Pin
Brisingr Aerowing7-May-15 4:21
professionalBrisingr Aerowing7-May-15 4:21 
GeneralRe: How to run a setup file in different sysytem.. Pin
ZurdoDev7-May-15 6:00
professionalZurdoDev7-May-15 6:00 
QuestionRe: How to run a setup file in different sysytem.. Pin
ZurdoDev7-May-15 4:06
professionalZurdoDev7-May-15 4:06 
QuestionC# web browser Pin
Jonteepersson967-May-15 1:56
Jonteepersson967-May-15 1:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.