JDBC MySQL connection using Unix Socket

If you want to use UNIX sockets with the Mysql JDBC Connector/J you need to provide a socketFactory. jdbc:mysql:///?user=test&password=test&socketFactory=<classname>&<socket>=/tmp/mysql.sock So this will vary with the implementation you use. By default, Mysql does not ship with any implementation for that, just provides an example for such a factory in it’s source-code. There is an existing UNIX … Read more

ObjectInputStream(socket.getInputStream()); does not work

The ObjectInputStream constructor reads data from the given InputStream. In order for this to work, you must flush the ObjectOutputStream immediately after construction (to write the initial header) before you attempt to open the ObjectInputStream. Also, if you want to send more than one object per connection, you must open the ObjectOutputStream once and use … Read more

C# Socket.BeginReceive/EndReceive

The order in time should be: BeginReceive for message length EndReceive for the completion of #1 BeginReceive for the message body EndReceive for the completion of #3 E.g. not using callbacks you could have: var sync = socket.BeginReceive(….); sync.AsyncWaitHandle.WaitOne(); var res = socket.EndReceive(sync); sync = socket.BeginReceive(….); sync.AsyncWaitHandle.WaitOne(); var res2 = socket.EndReceive(sync); But then, you would … Read more

WinError 10049: The requested address is not valid in its context

from socket import * soc = socket(AF_INET, SOCK_STREAM) soc.connect((‘168.62.48.183’, 80)) soc.send(‘GET /miners/get?file=BFGMiner-3.99-r.1-win32.zip HTTP/1.1\nUser-Agent:MultiMiner/V3\nHost: www.multiminerapp.com\n’) with open(“http-response.txt”,”w”) as respfile: response = soc.recv(1024) # <— Use select.epoll or asyncore instead! respfile.writelines(response) The reason for why your code fails tho is because you’re trying to bind to an external IP. Your machine is not aware of this IP … Read more

How Can I Access an SSL Connection Through Android?

1) It depends. Do you have a self signed cert on the server side and you are trying to validate your identity to the android device? Or are you on the android side trying to validate your idendity to the server? If it is the former , then please see this link: http://www.codeproject.com/KB/android/SSLVerification_Android.aspx?display=Mobile You want … Read more

passing a struct over TCP (SOCK_STREAM) socket in C

You need the following to portably send struct’s over the network: Pack the structure. For gcc and compatible compilers, do this with __attribute__((packed)). Do not use any members other than unsigned integers of fixed size, other packed structures satisfying these requirements, or arrays of any of the former. Signed integers are OK too, unless your … Read more

How to Run Only One Instance of Application

You may used named mutex. Code sample from the article: WINAPI WinMain( HINSTANCE, HINSTANCE, LPSTR, int) { try { // Try to open the mutex. HANDLE hMutex = OpenMutex( MUTEX_ALL_ACCESS, 0, “MyApp1.0”); if (!hMutex) // Mutex doesn’t exist. This is // the first instance so create // the mutex. hMutex = CreateMutex(0, 0, “MyApp1.0”); else … Read more

How can I get all the active TCP connections using .NET Framework (no unmanaged PE import!)?

I’m surprised with the quantity of users telling me that was not possible to do with pure managed code… For future users who is wondering about that, find the details from the answer that worked fine for me: //Don’t forget this: using System.Net.NetworkInformation; public static void ShowActiveTcpConnections() { Console.WriteLine(“Active TCP Connections”); IPGlobalProperties properties = IPGlobalProperties.GetIPGlobalProperties(); … Read more